ActionScript 3.0 :: Detecting Keys Pressed?
Jun 15, 2011Im unclear why this code is not working? What am i doing wrong?
ActionScript Code:
import flash.ui.Keyboard;
import flash.events.KeyboardEvent;
[code].....
Im unclear why this code is not working? What am i doing wrong?
ActionScript Code:
import flash.ui.Keyboard;
import flash.events.KeyboardEvent;
[code].....
How do you detect when to keys are pressed together. For example, if I press W and E together, I want something to happen. How do I do that?
View 5 RepliesI have it like this so far:
ActionScript Code:
stage.addEventListener(KeyboardEvent.KEY_DOWN, KeyPressed);
stage.addEventListener(KeyboardEvent.KEY_UP, KeyReleased);
public function KeyPressed(event:KeyboardEvent):void
[Code]....
and so far it works good, except when I press shift. If I'm holding the left or right arrow key and then I press shift, the object stops moving and doesn't do anything. However, if I release the arrow key and THEN press and hold shift, it works perfectly. How can I make it so that I can press shift while I'm holding the arrow key and still have it work?
I am struggling a bit with keys on the keyboards controlling a movieclip to happen.Ive got a person moving when pressing right and left, and a movieclip with three frames: First frame is a movieclip with the person standing still, looking bored. The second frame is the person moving right, and the third frame is the person moving left.This is the code that Ive inserted into the persons actions on scene1:
if (Key.isDown(Key.RIGHT)) {_x += speed;this.gotoAndStop(2);_xscale = +scale;}
if (Key.isDown(Key.LEFT)) {_x -= speed;this.gotoAndStop(3);_xscale = -scale;}
this code works alright accept that when the keys are not pressed it doesnt stand still, the legs are still moving, so I tried to include this code aswell:
if (!Key.isDown(KEY.RIGHT)) [code]....this makes the person standing still when not pressed but not moving the legs when turning right and left.
Can I track the keys pressed, using ActionScript?
View 1 Repliesif (Key.isDown(Key.RIGHT)and (Key.isDown(Key.LEFT){
trace("both pressed");
i am trying to write the syntax to detect left and right cursor keys .pressed down at same time.
I am doing a Flash game for school with parallax scrolling. Though I am going a much simpler way of the art, I am having one major error. My error is that when I stop pressing the Up Arrow Key, my ship does not move. All that my ship does, is sit there doing nothing, except for the following; exhausting fuel and showing the flame animation. Detecting if the Up Arrow Key (evt.keyCode == 38), I have tried both code below:
ActionScript Code:
!evt.keyCode == 38
and
ActionScript Code:
evt.keyCode != 38
I want to use the on device keys of the samsung (and other) tab devices {Home, return/back and menu} How do i listen to those/ what events are that? Googling it i have a hard time finding anything. Probably because i am not using the right phrase for it.
View 8 RepliesCannot Detect All Key pressed onKeyDown
Here is the code I used:
Code:
var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
trace("DOWN -> Code: " + Key.getCode() + " ACSII: " + Key.getAscii() + "
[Code]....
It is an usual code to listen the key presed on the keyboard. For some reason, I cannot detect any letter-key exept letters "w", "x", "d" and "J". I tested it on a different computer and results are the same. It is driving me crazy. I am not sure what is the problem.
I'm developing a little game. I use the following code to detect the keys pressed by the player:
[Code]...
Basically the shootKey will be hold down by the player almost all the time. And the changeColorKey will be pressed very often but not hold down. While testing I noted that holding the shootKey and the right arrow down, the onKeyUp events for the changeColorKey don't get fired. Holding the up or down arrow key instead of the right arrow has the same effect. If I hold the left arrow key the events get fired. Why does it occour? Is there something wrong with my code?
I want this code to move my map i.e map_mc when the keyboard keys are pressed. When I add it to the map_mc, I see no effect what do u think I am messing with.
Code:
on (keyPress "<Left>") {
currentX = this._x;
this._x = currentX - 2;
} on (keyPress "<Right>") {
currentX = this._x;
this._x = currentX + 2;
} on (keyPress "<Up>") {
currentY = this._y;
this._y = currentY - 2;
} on (keyPress "<Down>") {
currentY = this._y;
this._y = currentY + 2; }
I've followed the thread there: [URL]
I understand that this class allow the script to detect when keys are pressed in combination.
But what is exactly the implementation when a key is used both in single and combination states. Let's say that you've the "q" key used alone and "shift-q"...how would one proceed to achieve this detection?
In AS2 I did this:
ActionScript Code:
ContactVerDoor.onRelease = function() {
if (Key.isDown(Key.SPACE)) if (Key.isDown(Key.SHIFT)) {
//Do something
}
}
I now need to code it in AS3.Can I still check if a key is down without listening for the keypress events? I understand how to code the Mouseclick in AS3.
I want to be able to detect when a certain key is pressed. Not the preset ones like spacebar, enter, delete, left, right, etc... I want to make it so that when the letter "a" is pressed, then such and such happens, and if the letter "m" is pressed, another thing happens.
View 3 RepliesI want to detect which keys are pressed while user input text into TextField.I tried something like
import flash.text.TextFormat;
import flash.text.TextField;
import flash.events.Event;[code].......
but this doesn't work.
ive tested my game on several different computers. it works well on my desktop, but 2 laptops suffer an issue when left, space and up are all simultaneously pressed... thus the character is unable to move, jump and shoot at the same time
View 2 RepliesCreate a listener that will wait for a combo of keys pressed to launch a command? Something like if they type "admin" it will trigger a function.
View 2 Repliesin actionscript, Is there a way i can make a coddition happen if 2 keys at once are pressed?
example:
if (Key.isDown(Key.SHIFT) && (Key.isDown(Key.LEFT) && _currentframe == 1)) {
gotoAndPlay("running_left");
} else if (Key.isDown(Key.RIGHT) && (Key.isDown(Key.RIGHT) && _currentframe == 1)) {
gotoAndPlay("running_right");
}
or can't i do shift and left/right?
Im having a problem getting responsive keyboard movement. I have a key_up listener which fails to trigger when 3 keys are down. E.g. Imagine up and right keys are being pressed to move up + right. The user wants to change to moving up + left. The user presses the left key before lifting thg right key. I have a key_up listener to detect when a key is no longer being pressed. However in this scenario it fails to trigger when 3 keys are pressed. Even in this online example, there is the same problem, look how unresponsive it is when chaging from up right to up left really quickly. [URL]
[Code]...
I need to find a way to detect if the middlemouse button(Mouse 3) is pressed, I have tried to use ASnatives and it worked well..but once you fire up the flash stage in a fullscreen mode the ASnative seams to stop working or any other way of detecting the mousebutton?
View 0 RepliesIs it possible to detect when a user is clicking while simultaneously pressing a button on the keyboard? For instance, if a user presses "a" on the keyboard and then clicks on a specific movie clip, I'd like to trigger an animation.
View 3 Replieswhether using a String as the key in a Dictionary results in slower lookups than using an Object, Class or Custom Object (an instance of developer defined Type)?
When using a String as a key, does the literal String have to be parsed, or does the Dictionary key point to the String Object?
How do I get the AWSD keys to work as smoothly as the arrow keys. I can put the arrow keys inside an enterFrame
[AS]onClipEvent (enterFrame) {
//move the tank
if (Key.isDown(Key.RIGHT)) {
[Code]....
If I put the AWD keys inside an enterFrame they run until I push another button
I have a function on root:
_root.fadeBox_mc.onEnterFrame = function (){
if (fade){
this.nextFrame();[code]....
This causes a mc to fade in and out on rollover/rollout. But what I wanna make is a box that fades in when pressed on the button and fade out when pressed for the second time. But if I say
on (press){
_root.fade = true;
}
the mc fades in, but I cant do another on (press) to fade out. Is this too confusing?
My code doesnt detect 2 kest at once.I want to press an arrow key and spce bar. In .net the below code does do this but in flash if I hold down an arrow key and press space bar the arrow key event will stop working.[code]
View 7 Repliesin AS2 how would i use the down arrow key to make the timeline play? at the moment i have this and i presume i need to put something after that to make it play. [code]but i presume this is totaly wrong because the "stop();" doesnt stop the clip when the "if (Key.isDown(40))" bit is after it.
View 2 RepliesI have a quiz projector file in full screen. I want to prevent students from using keyboard shortcuts like alt+tab or the win key.[code]...
View 1 RepliesHow do I check wheter KEY_DOWN is false on every key on the keyboard? (no keys are pressed)
View 3 Repliesis it possible to set the state of keys rather than just read them in AS3? I am particularly interested in setting the state of the CAPS LOCK, NUMBER LOCK and SCROLL LOCK if possible i.e. toggling the LED state.
View 2 Repliesusing the authoring tool to test,I find I can only read certain keys via:stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDown);
But when I test in a browser, I can indeed read all the keys. So the IDE must be intercepting certain keypresses. E.g., I can read w and d but not e.
How can I read all keys? Testing in a browser all the time is a bit inconvenient