Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: restricting a particular key stroke or key code

  1. #1
    Java kindergarten chronoz13's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    659
    Thanks
    177
    Thanked 30 Times in 28 Posts

    Default restricting a particular key stroke or key code

    hi guys

    is there a shortcut (algorithm) to restrict a certain key events

    ex: assuming that e is a KeyEvent object

    if (e.getKeyCode() == KeyEvent.VK_ENTER ||
    e.getKeyCode() == KeyEvent.VK_SPACE ||
    e.getKeyCode() == KeyEvent.VK_BACKSPACE ) {

    // do something
    }


    or in a pseudocode style

    1) if keycode is not equal to space bar or enter or shift or tab f2 or f3
    3) if keycode is ONLY equal to Space bar and enter and shift and tab
    2) if keycode is ONLY equal to alphabet

    i can make a huge if statement to accomplish what i need. (though im not yet trying it but it will eat all my spaces on my code.

    is there atleast a short way to do what i want to do in here?

    thanks


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,327
    Thanks
    181
    Thanked 828 Times in 771 Posts
    Blog Entries
    5

    Default Re: restricting a particular key stroke or key code

    Not fully sure what you are asking...but it seems the first two are easily covered with the code you posted (not that long). For the last, the VK_* are sequential numbers, so just use a >= VK_A && <= VK_Z

  3. The Following User Says Thank You to copeg For This Useful Post:

    chronoz13 (April 22nd, 2011)

  4. #3
    Java kindergarten chronoz13's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    659
    Thanks
    177
    Thanked 30 Times in 28 Posts

    Default Re: restricting a particular key stroke or key code

    >= VK_A && <= VK_Z
    oh yes the answer is already there.. i forgot VK are all represented by integer... how dumb i didnt notice it

    got it got it.. thanks bro