www.webdeveloper.com
Results 1 to 4 of 4

Thread: Capture two keys at same time

  1. #1
    Join Date
    Sep 2006
    Location
    Cleveland
    Posts
    579

    Capture two keys at same time

    Is there a way to capture 2 keys pressed at the same time? For example crtl and another key. Thanks for the reply.

  2. #2
    Join Date
    Feb 2006
    Posts
    2,927
    No matter how quick you are, key events are received one at a time,
    if you pressed 10 keys at once they would be processed in a queue.

    When a keydown or keypress is handled you can look at
    some boolean properties of the event:
    ctrlKey,shiftKey,altKey each return true if the corresponding key was depressed
    when the key event was handled.

    Or you can build an array of key's on every keydown and wait to process them all when the next keyup event occurs.
    Last edited by mrhoo; 12-20-2006 at 12:43 PM.

  3. #3
    Join Date
    Mar 2005
    Location
    Sydney, Australia
    Posts
    7,974
    The shift, alt and ctrl keys work differently than the other keys in that they each set a separate flag in Javascript to indicate whether they are currently activated or not. It is therefore possible to test whether these keys are depressed and at the same time test for what other key is pressed. It is not possible to test for any multiple key press combination other than those that involve one or more of these three keys and one other key.
    Stephen

  4. #4
    Join Date
    Sep 2006
    Location
    Cleveland
    Posts
    579
    mrhoo and felgall

    Thanks for the reply. I was not sure if the bool for the crtl, shift, and alt were actually triggered from false to true until the key was either up to down or down to up. And to the point of making an array, I suppose pushing and popping would not be bad either if you would want to use different keys. Thanks again for the replys. This forum has the best people invovlved you two being on the list obviously. Have a great holiday.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles