Jump to content
  • Advertisement
Sign in to follow this  
  • entries
  • comments
  • views

Bonsai - input!

Sign in to follow this  


So, after some ha><0ring and general stuff I've got keyboard input working [smile]

The 3 basic windows keyboard messages as passed on;
- key down
- key up
- char

To go with this there are 3 translation tables;
- bonsai.Event.translate does int => string translation
- bonsai.Event.keycodes does string => int translation
- bonsai.Event.charTranslate also does int => string but the output is printable

The first two are mostly useful for game input, for example you could define the following somewhere

up = w
down = s
left = a
right = d
fire = space

Then, by performing a lookup against the current keycodes you can get the required values to check on event handling.

Then when you save out the config you can just push the keycodes into the translate table and get back the string which will translate back to it.

Simple and pretty easy [smile]

The 'bonsai.Event.charTranslate' does printable translations, namely for when shift matters [grin]
So, typing 'a' and typing 'A' will give you the correct results.
However, if you try to type '!' it kinda blows up atm, that's mostly due to the lack of translation causing 'nil' to be appended to my string which I try to print with the following main loop;

quit = false
text= ""
while(quit == false)
events = bonsai.getEvents()
for i = 1, #events
if events.message == bonsai.Event.types.quit
quit = true
if events.message == bonsai.Event.types.char
text = text .. bonsai.Event.charTranslate[events.param1]




This is just a basic test of things, and I'm pretty happy with it. I should probably fix that exploding translation problem so it does the Right Thing(tm) and I'm also going to have to do something about the shift characters depending on the keyboard layout in use (damn you non-UK layout people! *shakes fists*).

However, that's another tick on my 'todo' list done, huzzah!

I think that pretty much leaves colour constants and sprites to deal with and then the game can be recreated.

Sign in to follow this  


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!