Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (529)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Scan keypad keys without Num-Lock?  (Read 2124 times)
0 Members and 1 Guest are viewing this topic.
Offline Preston

Senior Member


Medals: 4



« Posted 2003-12-01 10:42:03 »

Is it possible to scan the keypad keys with a standard Swing/Awt KeyListener derivation, no matter if Num_Lock is enabled or disabled?
Currently I fail with that: you've to press the Num-Lock key in order to be able to scan the keys with KeyEvent.VK_NUMPAD1..9 etc. If Num-Lock is disabled they keypad keys act as cursor keys/Pageup/down etc, which isn't what I want to have.

A second question: if you want your overwritten keyPressed method to store any pressed key in a look-up table (array) is it OK to size that array at start-up time to the KeyEvent.KEY_LAST number? Or is this a "don't do this ever" thing? :)
Offline Preston

Senior Member


Medals: 4



« Reply #1 - Posted 2003-12-02 06:49:43 »

So... is it not possible to distinguish between Keypad_4 and the left-arrow-key when Num-lock is disabled?
(With a KeyEvent being fired be the KeyListener.keyPressed() method)

The underlying OS can do this however, so it should be possible with Java, too. Probably I'm looking into the wrong method?
Offline kevglass

JGO Kernel


Medals: 115
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #2 - Posted 2003-12-02 07:03:55 »

Actually, no, I don't think this is possible with Java "raw". KeyEvent abstracts the keyboard since the cursor left and the num-pad 4 might not be combined on some keyboards.

However, JInput could do this for you. But its quite an overhead to bring in for this..

Have you experimented with the KeyListener/KeyEvent stuff to see what you actually get?

Kev

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Preston

Senior Member


Medals: 4



« Reply #3 - Posted 2003-12-02 13:53:28 »

Quote
Actually, no, I don't think this is possible with Java "raw". KeyEvent abstracts the keyboard since the cursor left and the num-pad 4 might not be combined on some keyboards.

I see. That's a pity, but anway thanks for the info.

Quote
However, JInput could do this for you. But its quite an overhead to bring in for this..

Another native lib. Too much hassle actually - if avoidable.

Quote
Have you experimented with the KeyListener/KeyEvent stuff to see what you actually get?

Yes: with disabled num-lock key (the one with a yellow LED which is off now) I hit the keypad_4 key but get the KeyEvent.VK_LEFT, like if I had hit the left arrow key. :-)  And so on.
With enabled num-lock key the keypad_4 reports the KeyEvent_VK_NUMPAD4 as expected.

Has this been your question or did I misunderstand you?

Anway, this is no WYSIWYG. It's rather WYSIWYGBJWNE: What You See Is What You Get But Just With Numlock Enabled. ;-)
Offline tortoise

Junior Member




<3 Shmups


« Reply #4 - Posted 2003-12-02 18:05:54 »

Are you sure that is the case? Because it really doesn't make sense. An application should be able to receive events from both the keypad and arrow keys, regardless of numlock state.

According to the Javadocs, pressing numpad4 when numlock is off should result in VK_KP_LEFT, not VK_LEFT.

If that's the case (and I'm willing to bet it is), just tie VK_KP_LEFT and VK_NUMPAD4 together. If you ever ever get either event, you know they're generated from the same key.


EDIT: Ah, but then people are complaining that VK_LEFT is always returned, and never VK_KP_LEFT. Perhaps this is a lil bug in key events?
Offline kevglass

JGO Kernel


Medals: 115
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #5 - Posted 2003-12-02 18:23:45 »

Coo, well that teaches me not read the docs!

Kev

Offline Preston

Senior Member


Medals: 4



« Reply #6 - Posted 2003-12-02 18:49:11 »

Quote
Are you sure that is the case?

Yes. On my Win2000 with Java JRE v1.42_02-b03 it's the case.
Quote
According to the Javadocs, pressing numpad4 when numlock is off should result in VK_KP_LEFT, not VK_LEFT.

Here it does result in VK_LEFT.
With numlock enabled, it results in VK_NUMPAD4.
The code VK_KP_LEFT I never receive.

Quote
EDIT: Ah, but then people are complaining that VK_LEFT is always returned, and never VK_KP_LEFT. Perhaps this is a lil bug in key events?

This I don't understand I'm afraid... :-)


PS: Maybe some people could confirm their keypad's keycode behaviour, please? (different JREs, maybe, different platforms?)

The code I use fo this is like the following, attached to a GLCanvas
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
myGLCanvas.addKeyListener(new Listentome());

...

class Listentome implements KeyListener
{
  public void keyPressed(KeyEvent eve)
  {
    int keycode = eve.getKeyCode();
    // keycode then is is VK_blabla
 }
Offline tortoise

Junior Member




<3 Shmups


« Reply #7 - Posted 2003-12-02 19:11:44 »

Yeah, I always get VK_LEFT and not VK_KP_LEFT. Seems wrong to me. The javadocs say

Quote

VK_KP_LEFT
         Constant for the numeric keypad left arrow key.

VK_LEFT
         Constant for the non-numpad left arrow key.


That's pretty clear IMO.

I'm using Sun's java 1.4.2 for Windows.


The part you didn't understand, I was just saying it looks like a bug.
Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #8 - Posted 2003-12-03 02:02:10 »

It is a bug that will not be fixed... the work around is to use:getKeyLocation() on the KeyEvent.
It should return       KEY_LOCATION_NUMPAD

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

ctomni231 (31 views)
2014-07-18 06:55:21

Zero Volt (27 views)
2014-07-17 23:47:54

danieldean (23 views)
2014-07-17 23:41:23

MustardPeter (24 views)
2014-07-16 23:30:00

Cero (39 views)
2014-07-16 00:42:17

Riven (41 views)
2014-07-14 18:02:53

OpenGLShaders (28 views)
2014-07-14 16:23:47

Riven (28 views)
2014-07-14 11:51:35

quew8 (25 views)
2014-07-13 13:57:52

SHC (61 views)
2014-07-12 17:50:04
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!