Best approach for keyboard events...
Posted: Sat Feb 19, 2011 1:11 am
Hi all,
Been sick the past few days, decided to take a break from my video app, and try and skeleton a basic GUI for that Text RPG I've been planning. But then I kind of ran into a hitch I didn't expect. Trapping key press events, in a way that is preferably cross-platform (I'd like to potentially release the game for both Windows and Linux), and doesn't interfere with normal operation of OS functions like ALT+TAB switching, or other functions within the games GUI window in general..
Some forum searches got me lots of lines of codes, and various methods, as well as strong opinions; but I think it left me more uncertain!
The Keyboard library doesn't seem much use in this case, as it seems to be intended for console applications, or 2D apps using an open "Screen".
I'm not sure Shortcutkeys are want I want at all, although I could use them for some functionality such as firing macros... I am after a certain functionality in particular, however.
Here is a basic outline of some functionality I was thinking of.
For the very basics, I have an editor gadget that will function as the main display window (read only), and then a StringGadget which I will use for user input. I would like to trap the Enter key in this case, so that when the user enters some text, it sets off an event that will grab that text into a variable, clear the input box, and pass the text in the variable on to the command parser.. A rather typical behavior I suppose.
I also like the behavior most applications have, where if you hit Enter when you're in a subwindow/menu etc.. it defaults as the "user has hit OK button" action, closes that menu, etc.. I've seen one example of using the keyboard to navigate a GUI and set off button presses, but it looked pretty long and a bit intimidating/complicated.
However in terms of "where to start", I am looking for some basic advice on things I should investigate/research.. If anyone wants to provide a basic event loop sample, that would probably help a little.. But also keep in mind, I am looking for something that can work on both Windows & Linux, without any major hiccups / hacks needed..
I thought about using SDL.. but it looks like for Windows I'd have to go through the annoyances of downloading SDL and then wrapping it with prototypes, etc.. Kind of a shame because from what I read PB uses it natively for Linux compiles.. But it provides low level access to so much stuff it seems like a really useful too, even if you don't need it for its graphics rendering purposes.
Anyway.. Advice/examples/pointers in the right direction are all appreciated..
Been sick the past few days, decided to take a break from my video app, and try and skeleton a basic GUI for that Text RPG I've been planning. But then I kind of ran into a hitch I didn't expect. Trapping key press events, in a way that is preferably cross-platform (I'd like to potentially release the game for both Windows and Linux), and doesn't interfere with normal operation of OS functions like ALT+TAB switching, or other functions within the games GUI window in general..
Some forum searches got me lots of lines of codes, and various methods, as well as strong opinions; but I think it left me more uncertain!
The Keyboard library doesn't seem much use in this case, as it seems to be intended for console applications, or 2D apps using an open "Screen".
I'm not sure Shortcutkeys are want I want at all, although I could use them for some functionality such as firing macros... I am after a certain functionality in particular, however.
Here is a basic outline of some functionality I was thinking of.
For the very basics, I have an editor gadget that will function as the main display window (read only), and then a StringGadget which I will use for user input. I would like to trap the Enter key in this case, so that when the user enters some text, it sets off an event that will grab that text into a variable, clear the input box, and pass the text in the variable on to the command parser.. A rather typical behavior I suppose.
I also like the behavior most applications have, where if you hit Enter when you're in a subwindow/menu etc.. it defaults as the "user has hit OK button" action, closes that menu, etc.. I've seen one example of using the keyboard to navigate a GUI and set off button presses, but it looked pretty long and a bit intimidating/complicated.
However in terms of "where to start", I am looking for some basic advice on things I should investigate/research.. If anyone wants to provide a basic event loop sample, that would probably help a little.. But also keep in mind, I am looking for something that can work on both Windows & Linux, without any major hiccups / hacks needed..
I thought about using SDL.. but it looks like for Windows I'd have to go through the annoyances of downloading SDL and then wrapping it with prototypes, etc.. Kind of a shame because from what I read PB uses it natively for Linux compiles.. But it provides low level access to so much stuff it seems like a really useful too, even if you don't need it for its graphics rendering purposes.
Anyway.. Advice/examples/pointers in the right direction are all appreciated..