View Full Version : [AS3] Keyboard & Mouse Events
Axonn
09-10-2009, 01:23 PM
Hi everybody. I'm working at a game, and as expected, having a hell of a time with events.
1. The first problem is that the KEY_UP keyboard event does NOT work as you might expect for CTRL and SHIFT. The 2 flags are ALWAYS FALSE when this event returns. However, the keyCode is indeed correct, 17 for CTRL and 16 for SHIFT. On Windows. Can anybody tell me what those key codes are on Mac or Linux? Because I would hate my game to behave differently there.
2. The other interesting thing is that MOUSE_DOWN only executes once, when you first press the mouse button. If you keep it pressed, nothing else happens. However, KEY_DOWN fires continuously for as long as the keyboard key is pressed.
I find all this rather inconsistent. Shame to Adobe or shame on me for not understanding it right? ::- D.
Axonn
09-10-2009, 03:03 PM
I will have to repeat my message because I don't understand why the moderator buried my thread into the less-used Forum section of Game Development. So what if I said that I'm working at a game? My question was GENERAL. When am I going to receive an answer if I'm moved to god-knows what section nobody goes into. Please don't move messages without reading them because you're harming the Forum.
So... maybe now somebody can talk to me ::- ).
1. The first problem is that the KEY_UP keyboard event does NOT work as you might expect for CTRL and SHIFT. The 2 flags are ALWAYS FALSE when this event returns. However, the keyCode is indeed correct, 17 for CTRL and 16 for SHIFT. On Windows. Can anybody tell me what those key codes are on Mac or Linux? Because I would hate my game to behave differently there.
2. The other interesting thing is that MOUSE_DOWN only executes once, when you first press the mouse button. If you keep it pressed, nothing else happens. However, KEY_DOWN fires continuously for as long as the keyboard key is pressed.
I find all this rather inconsistent. Shame to Adobe or shame on me for not understanding it right? ::- D.
bloodsample
09-10-2009, 04:17 PM
1. The flags shiftKey and ctrlKey from the KeyboardEvent are used to see if the SHIFT or CTRL keys are being held down as another key fires the event. Since you're using KEY_UP, when you hold down on a key the event hasn't fired yet until you release the key. So if you just press SHIFT (or CTRL) then shiftKey (or ctrlKey) will be FALSE in your KEY_UP event because they are not being held down. shiftKey (or ctrlKey) will only be true if you hold SHIFT (or CTRL) as you press another key. Hope that made sense. I'm not sure about MAC vs Windows keyCodes.
2. The repetition of KEY_DOWN events has nothing to do with adobe. When you hold a key on your keyboard, that key gets sent repeatedly to your computer via an internal clock. When you hold down a key in notepad for example, you will get multiple instances of the key you pressed. The mouse only sends one event as the button is being pressed however. Otherwise you'd end up always double clicking on things if you held the button for too long.
CyanBlue
09-10-2009, 04:26 PM
I have merged/moved your threads to Gaming and Game Development because this forum fits your question the best... I know that your question fits more than one forum, but it is for the best interest of the all the users in the forum...
Axonn
09-10-2009, 05:06 PM
CyanBlue: *sigh* I got nothing against order. But there are very few viewers here. I would suggest moving topics AFTER they have been answered, that would benefit both ::- ). Just a friendly idea ::- ). I'm not having the hatchet in my hand or anything ::- D.
bloodsample:
2. Makes perfect sense (now that you mention it). I've been doing plenty of WIN32 API programming in C++ and that's the way Windows behaves, yes. It just seemed inconsistent at the moment.
1. Makes sense, yes.
Thanks for your answer ::- ).
Anybody know the key codes for Mac? Linux I guess is the same as Windows since it's PC?
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.