Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (292)
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 1603 times)
0 Members and 1 Guest are viewing this topic.
Offline Preston

Senior Member


Medals: 2



« 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? :)

Memento mori.
Offline Preston

Senior Member


Medals: 2



« 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?

Memento mori.
Offline kevglass
« League of Dukes »

JGO Kernel


Medals: 54
Projects: 20


Mentally unstable, best avoided.


« 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!
Try the Free Demo of Titan Attacks
Offline Preston

Senior Member


Medals: 2



« 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. ;-)

Memento mori.
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
« League of Dukes »

JGO Kernel


Medals: 54
Projects: 20


Mentally unstable, best avoided.


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

Coo, well that teaches me not read the docs!

Kev

Offline Preston

Senior Member


Medals: 2



« 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
 }

Memento mori.
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.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Get high quality music tracks for your game!

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

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (66 views)
2013-05-17 21:29:12

alaslipknot (75 views)
2013-05-16 21:24:48

gouessej (107 views)
2013-05-16 00:53:38

gouessej (103 views)
2013-05-16 00:17:58

theagentd (114 views)
2013-05-15 15:01:13

theagentd (103 views)
2013-05-15 15:00:54

StreetDoggy (148 views)
2013-05-14 15:56:26

kutucuk (171 views)
2013-05-12 17:10:36

kutucuk (169 views)
2013-05-12 15:36:09

UnluckyDevil (178 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.099 seconds with 21 queries.