View Full Version : assigning actions to keyboard keys??
dragnfyr90
01-18-2002, 05:50 PM
this may be a simple question, but how do you assign a key to do something, example- say i wanted to push the x button and have it go to frame 20 and play, or do anything really, i just want to be able to make a key act the same way as a button without having to use the mouse.
thanks for any help
-mike
jimburton
01-18-2002, 08:18 PM
You can either do this with a button or, even better, with movieclip watching for the keydown or keyup event, something like:
onClipEvent (keyUp) {
if(Key.getCode() == 88 || Key.getCode() == 120) {
trace("x was pressed!");//do whatever you want
}
}
use keyUp to check whether something was pressed and a combination of keyDown and Key.isDown to check continuous holding down of a key (ie for direction of a moving clip in a game...)
Here's the easiest way to do it.
How? Real easy! Make a button and place it off-stage anywhere. Then open the basic actions menu and select "onmouseevent". There is an option for a keyboard key in there.
If you want more keys to do more things, just add more of the same action to the button. It will wait off stage for you to hit the keys anytime!
I hope this helps!
dragnfyr90
01-18-2002, 10:27 PM
ok but how do i link that to a button i already have created, i want the key to act as the mouse down, so when i press the key it acts as though i had the curser over it and pushed the button down.
i am sorry if this sounds dumb, but i have only been doing this for a few days. thanks
red penguin
01-19-2002, 01:22 AM
You can use exactly what jim said up there, yeah? But just put it on your button....
dragnfyr90
01-19-2002, 01:30 AM
ok but will that make the actual button react, like when you push down on a button it will play the sound that you have for the down section in the button timeline, all i want is for the button to react like it does when you use the mouse.
red penguin
01-19-2002, 01:48 AM
If you want a sound to play then you'd have to work with the sound object and in the code when the key is pressed, play that sound.
onClipEvent (keyUp) {
if(Key.getCode() == 88 || Key.getCode() == 120) {
//your executable code and ...
mySound = new Sound();
mySound.attachSound("click");
mySound.start();
}
}
Make sense?
dragnfyr90
01-19-2002, 04:02 PM
but dont you need a movie clip for that to work, i think you are going further than i need, i attached a file, when you click on the button it turns red and moos at you i want to make a key do just that, and that is all. i am sorry if the answer is right there in front of my face but i cant seem to get it to work, i have been up all night trying different things and i am just stuck.
thanks
jimburton
01-19-2002, 10:39 PM
I've put an example of what I was talking about in the attached copy of your fla - uses the code from my original response to have a movieclip mimic button behaviour in response to someone pressing the x key. Have a look at it. Buttons are pretty stupid really - they sit there waiting to be pressed and they have UP, OVER and DOWN states and that's all. To go any further look to movieclips. Hope this does it for you...:)
dragnfyr90
01-20-2002, 03:47 PM
ok I get it now, thank you very much.
vBulletin® v3.7.1, Copyright ©2000-2009, Jelsoft Enterprises Ltd.