Bugfix : properly handle control-modified keys

* GLUT sends the raw ascii ctrl-values, so we merely send them along in a "cooked" mode
        + It may be that some strange ctrl combinations (saw CTRL-~ or CTRL-ESC) are not properly handled this way, but
        ... not sure what can be done about this (doesn't seem to be a way to force glut to send us the non-cooked keys)
    * Legacy X11 input continues to be sent as raw values (which arguably is a better way)
This commit is contained in:
Aaron Culliney 2014-09-21 17:26:37 -07:00
parent db8ac1c98b
commit f794098a02
5 changed files with 24 additions and 16 deletions

View File

@ -167,13 +167,23 @@ int c_keys_is_shifted()
/* -------------------------------------------------------------------------
Handle input : keys and joystick.
------------------------------------------------------------------------- */
void c_keys_handle_input(int scancode, int pressed)
void c_keys_handle_input(int scancode, int pressed, int is_cooked)
{
int *keymap = NULL;
assert(scancode < 0x80);
if (scancode >= 0)
{
if (is_cooked) {
last_scancode = -1;
if (!pressed) {
return;
}
if (! (key_pressed[ SCODE_L_CTRL ] || key_pressed[ SCODE_R_CTRL ]) ) {
if (caps_lock && scancode >= 'a' && scancode <= 'z') {
scancode -= 32;
}
}
next_key = scancode;
} else if (scancode >= 0) {
last_scancode = scancode;
if ((key_pressed[ SCODE_L_SHIFT ] || key_pressed[ SCODE_R_SHIFT ]) &&

View File

@ -154,6 +154,6 @@ void c_keys_set_key(int key);
bool c_keys_is_interface_key(int key);
int c_keys_is_shifted();
int c_keys_ascii_to_scancode(int ch);
void c_keys_handle_input(int scancode, int pressed);
void c_keys_handle_input(int scancode, int pressed, int is_cooked);
#endif

View File

@ -145,30 +145,28 @@ static int _glutkey_to_scancode(int key) {
#if !defined(TESTING)
void gldriver_on_key_down(unsigned char key, int x, int y) {
_capslock_hackaround();
int scancode = c_keys_ascii_to_scancode(key);
//LOG("onKeyDown %02x '%c' -> %02X", key, key, scancode);
c_keys_handle_input(scancode, 1);
//LOG("onKeyDown %02x(%d)'%c'", key, key, key);
c_keys_handle_input(key, 1, 1);
}
void gldriver_on_key_up(unsigned char key, int x, int y) {
_capslock_hackaround();
int scancode = c_keys_ascii_to_scancode(key);
//LOG("onKeyUp %02x '%c' -> %02X", key, key, scancode);
c_keys_handle_input(scancode, 0);
//LOG("onKeyUp %02x(%d)'%c'", key, key, key);
c_keys_handle_input(key, 0, 1);
}
void gldriver_on_key_special_down(int key, int x, int y) {
_capslock_hackaround();
int scancode = _glutkey_to_scancode(key);
//LOG("onKeySpecialDown %08x -> %02X", key, scancode);
c_keys_handle_input(scancode, 1);
//LOG("onKeySpecialDown %08x(%d) -> %02X(%d)", key, key, scancode, scancode);
c_keys_handle_input(scancode, 1, 0);
}
void gldriver_on_key_special_up(int key, int x, int y) {
_capslock_hackaround();
int scancode = _glutkey_to_scancode(key);
//LOG("onKeySpecialUp %08x -> %02X", key, scancode);
c_keys_handle_input(scancode, 0);
//LOG("onKeySpecialDown %08x(%d) -> %02X(%d)", key, key, scancode, scancode);
c_keys_handle_input(scancode, 0, 0);
}
#endif

View File

@ -285,7 +285,7 @@ static void gldriver_init_common(void) {
static void gldriver_update(void) {
#if !defined(__APPLE__)
// HACK MAYBE FIXME : pumps the joystick sampling code that is currently integrated into the keys routine
c_keys_handle_input(-1, 0);
c_keys_handle_input(-1, 0, 0);
#endif
glutPostRedisplay();
}

View File

@ -472,7 +472,7 @@ void video_driver_sync(void) {
break;
}
c_keys_handle_input(scancode, pressed);
c_keys_handle_input(scancode, pressed, 0);
} while (keyevent);
#endif