Page 1 of 1

[fixed] EKEY_CODE in Keycodes.h has insufficient range

Posted: Thu Mar 16, 2017 9:58 am
by Klokancz
Enum EKEY_CODE for keyeboard input accepts only 255 codes.

Problem:
Presses of 'fn' button on notebook keyboard yields code 255. As far as KEY_KEY_CODES_COUNT = 0xff is used for KeyIsDown[KEY_KEY_CODES_COUNT]; the value ends in next variable. (In my case it was left mouse button clicked)

Code: Select all

 //problem
bool KeyIsDown[255];
KeyIsDown[255] = true; // problem here
 
Suggested fix:
Add fn key to the enum. Variable will support complete 8b input.

Code: Select all

        KEY_FN               = 0xFF,   // Function key on notebook
 
        KEY_KEY_CODES_COUNT  = 0x100 // this is not a key, but the amount of keycodes there are.
 

Re: enum EKEY_CODE in Keycodes.h has insuffitient range [1.8

Posted: Thu Mar 16, 2017 11:12 am
by CuteAlien
That is probably not the key-code (those have only 8 bit). Next bit is the one that tells that a key is an extended key. But fn key shouldn't even create a key-message I think. Unfortunately I can't test right now because the ssd of my laptop broke down and I didn't get around yet figuring out how to replace it.

Re: enum EKEY_CODE in Keycodes.h has insuffitient range [1.8

Posted: Thu Mar 16, 2017 5:51 pm
by Klokancz
Good 8 bit codes then it seems ok. 0xFF is the maximum value you can fit into 8 bit variable.
Image

Not to wast time with this there is some detail to array:

Code: Select all

char[1] //declared array for single character
char[255]//declared array for 255 characters - values from 0x0 to 0x254(this is 0xFE not full char 1111 1110 <- LSB is zero)
char[256]//declared array for 256 characters - values from 0x0 to 0x255(this is 0xFF)
 

Re: enum EKEY_CODE in Keycodes.h has insuffitient range [1.8

Posted: Thu Mar 16, 2017 6:56 pm
by CuteAlien
Ah, right. I suppose we should add 0xff as KEY_NONE (all names are based on the VK_ names from Windows) and then increase KEY_KEY_CODES_COUNT.

And with the KeyIsDown you mean the examples I guess?

Re: enum EKEY_CODE in Keycodes.h has insuffitient range [1.8

Posted: Thu Mar 16, 2017 10:43 pm
by CuteAlien
OK, I changed in svn 1.8 and trunk branches.