This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Cranium's profile picture

Key code bindings incorrect

Started by Cranium, 20 December 2012 - 02:01 PM
Cranium #1
Posted 20 December 2012 - 03:01 PM
I was trying to write a calculator program, and in doing some testing, I found that the key code bindings referenced in the keys api show different than what actually is returned using os.pullEvent().

I used the website documented in the api: http://www.minecraft.../wiki/Key_Codes

It shows that the numpad key code is to show as 156. However, when returning the keycode with os.pullEvent(), it returns 28, the same as the enter key on the keyboard.

Edit: I am using version 1.47 of CC.
Edited on 20 December 2012 - 02:01 PM
Cloudy #2
Posted 20 December 2012 - 08:50 PM
We get it straight from LWJGL. If its wrong in CC its actually wrong on the wiki.
theoriginalbit #3
Posted 20 December 2012 - 09:10 PM
Cranium why would you not use the keys API to check which key was pressed instead of using the numbers from the MC wiki? o.O Your using the latest version.
Doyle3694 #4
Posted 21 December 2012 - 03:46 AM
TOBIT, it's way eaiser then trying to figure out the name of the key in the keys API
PixelToast #5
Posted 21 December 2012 - 05:13 AM
i dont have CC open right now so i cant test .-.
why would you want to use the keypad anyway?
most laptops dont have those keys
Cranium #6
Posted 21 December 2012 - 06:29 AM
i dont have CC open right now so i cant test .-.
why would you want to use the keypad anyway?
most laptops dont have those keys
Not everyone uses laptops to play MC. I know some of our players feel more comfortable using a number pad to type equations.

Cranium why would you not use the keys API to check which key was pressed instead of using the numbers from the MC wiki? o.O Your using the latest version.
The keys API shows that the 'numpadenter' uses key 156.

I can code around this, but I just thought I would bring it up.
theoriginalbit #7
Posted 21 December 2012 - 11:47 AM
TOBIT, it's way eaiser then trying to figure out the name of the key in the keys API

Umm not its not, keys.a keys.escape, keys.enter, keys.backspace, keys.numpadenter…… whats so hard about that! Also there is the API file that you can open too.




The keys API shows that the 'numpadenter' uses key 156.

I can code around this, but I just thought I would bring it up.
Ahh ok, i was just curious since I dont have a numberpad and i didn't realise you were using it ;)/>
Cranium #8
Posted 21 December 2012 - 11:50 AM
Most desktop computer keyboards do have a number pad, and since I am used to using it at work for various calculations, I thought it would be something to check on, since I am getting the wrong number compared to the documentation.
AfterLifeLochie #9
Posted 21 December 2012 - 03:34 PM
Please keep in mind that we keep an up-to-date and almost guaranteed to be correct set of key codes on the ComputerCraft Wiki here (http://www.computercraft.info/wiki/Raw_key_events) - which I know work, because I use them myself.

If you still find these do not work, fire up another session in CC and do an os.pullEvent() to find out which keys you are actually being pressed - because unless LWJGL changed the way keys fire, or, your keyboard is not the standard US-English keyboard, you shouldn't have any issues IIRC.

Edit:
It shows that the numpad key code is to show as 156. However, when returning the keycode with os.pullEvent(), it returns 28, the same as the enter key on the keyboard.

Code 156 is NUMPAD_ENTER, Code 28 is just ENTER. For some obscure reason they're considered the same, so all ENTER buttons throw back a Code 28.
theoriginalbit #10
Posted 22 December 2012 - 01:31 PM
Edit:
It shows that the numpad key code is to show as 156. However, when returning the keycode with os.pullEvent(), it returns 28, the same as the enter key on the keyboard.

Code 156 is NUMPAD_ENTER, Code 28 is just ENTER. For some obscure reason they're considered the same, so all ENTER buttons throw back a Code 28.

So sounds more like a LWJGL bug to me, not a CC bug?
AfterLifeLochie #11
Posted 22 December 2012 - 01:36 PM
It is a LWJGL bug, and has been reported now.

In the meantime, use this: http://www.computercraft.info/wiki/images/8/81/CC-Keyboard-Charcodes.png
Cranium #12
Posted 22 December 2012 - 02:44 PM
Glad to know that my computer isn't broken. And thank you for reporting the bug with LWJGL
Noodle #13
Posted 22 December 2012 - 04:27 PM
And nobody thinks its better to have 28 be both? They both say enter..
If you do "Press enter to continue" and you have it set to numpad_enter then people will be confused.
PixelToast #14
Posted 22 December 2012 - 05:01 PM
or just use this awesome thing called

a==1 or a==2
Cranium #15
Posted 24 December 2012 - 11:15 AM
I did code my program to look for both, if they ever get updated, but I just thought that separate key codes for separate keys are a bit nicer. Some people use the numpad in gaming.
Cloudy #16
Posted 24 December 2012 - 11:17 AM
If you're getting 28 on both, WE'RE getting 28 on both. We pass the raw value we get in Java code back to you.
AfterLifeLochie #17
Posted 24 December 2012 - 11:23 AM
And nobody thinks its better to have 28 be both? They both say enter..
If you do "Press enter to continue" and you have it set to numpad_enter then people will be confused.
In the LWJGL and DirectX specifications, all keys have *unique* ID's - even if the key has the same function. The fact this bug (or accident) has appeared in LWJGL is coincidental, and should be fixed - incorporating checks for ENTER and NUMPAD_ENTER is advised - however, it could be a while until said "bug" is fixed.