]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
Some fixes to the keyboard handler:
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 4 Jun 2014 09:08:42 +0000 (09:08 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 4 Jun 2014 09:08:42 +0000 (09:08 +0000)
------- WGL -------
* Keyboard handler now returns Unicode chars
* Fix numlock key interpreted as pause key
* Fix numlock, scrollock and capslock binds not working
* When numlock is off numeric keypad keys now return K_END, K_DOWNARROW,
* etc... Previously they always returned K_KP_<num>
regardless of numlock state

------- SDL -------
* Simulate press and release events when numlock and capslock get
* pressed, so that they can work similarly to the other keys
(excluding key repetition, it doesn't and will never work). It's a
workaround for the default SDL behaviour with these keys:
it generate a press event when a key gets enabled, a release event when
the key gets disabled. Scrollock already works as a
normal key.
* When numlock is off numeric keypad keys now return K_END, K_DOWNARROW,
* etc... Previously they always returned K_KP_<num>
regardless of numlock state

------- GLX -------
* Add numlock, scrollock and capslock keys

From: terencehill <piuntn@gmail.com>

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12085 d7cf8633-e32d-0410-b094-e92efae38249

dpdefs/keycodes.qc
keys.c
vid_glx.c
vid_sdl.c
vid_wgl.c

index 65fe815b0001bf47080a06c3d9cb0796355b0f4f..7752f5090a114388ecf97bcf8adf56e6a095d934 100644 (file)
@@ -43,7 +43,7 @@ float K_END           =       152;
 
 float K_NUMLOCK                = 154;
 float K_CAPSLOCK       = 155;
-float K_SCROLLLOCK     = 156;
+float K_SCROLLOCK      = 156;
 
 float K_KP_0   =       157;
 float K_KP_INS =       157; // same as K_KP_0
diff --git a/keys.c b/keys.c
index 45d2daf85fdab1581b224cacd6c85eb0aac981d6..326485609b4e22b386212a16f2ec9e3658e40c84 100644 (file)
--- a/keys.c
+++ b/keys.c
@@ -1766,11 +1766,6 @@ Key_Event (int key, int ascii, qboolean down)
                return;
        }
 
-       if (ascii == 0x80 && utf8_enable.integer) // pressing AltGr-5 (or AltGr-e) and for some reason we get windows-1252 encoding?
-               ascii = 0x20AC; // we want the Euro currency sign
-               // TODO find out which vid_ drivers do it and fix it there
-               // but catching U+0080 here is no loss as that char is not useful anyway
-
        // get key binding
        bind = keybindings[key_bmap][key];
        if (!bind)
@@ -1781,7 +1776,7 @@ Key_Event (int key, int ascii, qboolean down)
 
        if(key_consoleactive)
                keydest = key_console;
-       
+
        if (down)
        {
                // increment key repeat count each time a down is received so that things
@@ -1805,7 +1800,7 @@ Key_Event (int key, int ascii, qboolean down)
 
        if(keydest == key_void)
                return;
-       
+
        // key_consoleactive is a flag not a key_dest because the console is a
        // high priority overlay ontop of the normal screen (designed as a safety
        // feature so that developers and users can rescue themselves from a bad
index 9e33fdc91f7fe5c631f1ef9a6ac284dca719abd2..8327b2608e9a8e301af2d7d27d0101c0e6a816fd 100644 (file)
--- a/vid_glx.c
+++ b/vid_glx.c
@@ -284,6 +284,10 @@ static int XLateKey(XKeyEvent *ev, Uchar *ascii)
                case XK_KP_Subtract: key = K_KP_MINUS; break;
                case XK_KP_Divide: key = K_KP_SLASH; break;
 
+               case XK_Num_Lock: key = K_NUMLOCK; break;
+               case XK_Caps_Lock: key = K_CAPSLOCK; break;
+               case XK_Scroll_Lock: key = K_SCROLLOCK; break;
+
                case XK_asciicircum:    *ascii = key = '^'; break; // for some reason, XLookupString returns "" on this one for Grunt|2
 
                case XK_section:        *ascii = key = '~'; break;
index 003f1ba884f9bd242a7b55522d71cddcb961f31e..d632a2b4b6d67ed0f1beb52388d1a680d85e6a23 100644 (file)
--- a/vid_sdl.c
+++ b/vid_sdl.c
@@ -231,18 +231,18 @@ static int MapKey( unsigned int sdlkey )
        case SDLK_KP_PLUS:            return K_KP_PLUS;
        case SDLK_KP_ENTER:           return K_KP_ENTER;
 #if SDL_MAJOR_VERSION == 1
-       case SDLK_KP_1:               return K_KP_1;
-       case SDLK_KP_2:               return K_KP_2;
-       case SDLK_KP_3:               return K_KP_3;
-       case SDLK_KP_4:               return K_KP_4;
+       case SDLK_KP_1:               return ((SDL_GetModState() & KMOD_NUM) ? K_KP_1 : K_END);
+       case SDLK_KP_2:               return ((SDL_GetModState() & KMOD_NUM) ? K_KP_2 : K_DOWNARROW);
+       case SDLK_KP_3:               return ((SDL_GetModState() & KMOD_NUM) ? K_KP_3 : K_PGDN);
+       case SDLK_KP_4:               return ((SDL_GetModState() & KMOD_NUM) ? K_KP_4 : K_LEFTARROW);
        case SDLK_KP_5:               return K_KP_5;
-       case SDLK_KP_6:               return K_KP_6;
-       case SDLK_KP_7:               return K_KP_7;
-       case SDLK_KP_8:               return K_KP_8;
-       case SDLK_KP_9:               return K_KP_9;
-       case SDLK_KP_0:               return K_KP_0;
+       case SDLK_KP_6:               return ((SDL_GetModState() & KMOD_NUM) ? K_KP_6 : K_RIGHTARROW);
+       case SDLK_KP_7:               return ((SDL_GetModState() & KMOD_NUM) ? K_KP_7 : K_HOME);
+       case SDLK_KP_8:               return ((SDL_GetModState() & KMOD_NUM) ? K_KP_8 : K_UPARROW);
+       case SDLK_KP_9:               return ((SDL_GetModState() & KMOD_NUM) ? K_KP_9 : K_PGUP);
+       case SDLK_KP_0:               return ((SDL_GetModState() & KMOD_NUM) ? K_KP_0 : K_INS);
 #endif
-       case SDLK_KP_PERIOD:          return K_KP_PERIOD;
+       case SDLK_KP_PERIOD:          return ((SDL_GetModState() & KMOD_NUM) ? K_KP_PERIOD : K_DEL);
 //     case SDLK_APPLICATION:        return K_APPLICATION;
 //     case SDLK_POWER:              return K_POWER;
        case SDLK_KP_EQUALS:          return K_KP_EQUALS;
@@ -1113,7 +1113,16 @@ void Sys_SendKeyEvents( void )
                        case SDL_KEYUP:
                                keycode = MapKey(event.key.keysym.sym);
                                if (!VID_JoyBlockEmulatedKeys(keycode))
+                               {
+                                       if(keycode == K_NUMLOCK || keycode == K_CAPSLOCK)
+                                       {
+                                               // simulate down followed by up
+                                               Key_Event(keycode, event.key.keysym.unicode, true);
+                                               Key_Event(keycode, event.key.keysym.unicode, false);
+                                               break;
+                                       }
                                        Key_Event(keycode, event.key.keysym.unicode, (event.key.state == SDL_PRESSED));
+                               }
                                break;
                        case SDL_ACTIVEEVENT:
                                if( event.active.state & SDL_APPACTIVE )
index 4ff183e705a08821accb5107d99744fa0f0ad7de..544d24ba27a6f1395abae691f953a7b9241f0b34 100644 (file)
--- a/vid_wgl.c
+++ b/vid_wgl.c
@@ -153,10 +153,11 @@ static qboolean vid_isfullscreen;
 //void VID_MenuDraw (void);
 //void VID_MenuKey (int key);
 
-//LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
-//void AppActivate(BOOL fActive, BOOL minimize);
-//void ClearAllStates (void);
-//void VID_UpdateWindowStatus (void);
+LONG WINAPI MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
+void AppActivate(BOOL fActive, BOOL minimize);
+static void ClearAllStates(void);
+qboolean VID_InitModeGL(viddef_mode_t *mode);
+qboolean VID_InitModeSOFT(viddef_mode_t *mode);
 
 //====================================
 
@@ -326,19 +327,17 @@ void VID_Finish (void)
 //==========================================================================
 
 
-
-
 static unsigned char scantokey[128] =
 {
-//  0           1       2    3     4     5       6       7      8         9      A          B           C       D           E           F
-       0          ,27    ,'1'  ,'2'  ,'3'  ,'4'    ,'5'    ,'6'   ,'7'      ,'8'   ,'9'       ,'0'        ,'-'   ,'='         ,K_BACKSPACE,9    ,//0
-       'q'        ,'w'   ,'e'  ,'r'  ,'t'  ,'y'    ,'u'    ,'i'   ,'o'      ,'p'   ,'['       ,']'        ,13    ,K_CTRL      ,'a'        ,'s'  ,//1
-       'd'        ,'f'   ,'g'  ,'h'  ,'j'  ,'k'    ,'l'    ,';'   ,'\''     ,'`'   ,K_SHIFT   ,'\\'       ,'z'   ,'x'         ,'c'        ,'v'  ,//2
-       'b'        ,'n'   ,'m'  ,','  ,'.'  ,'/'    ,K_SHIFT,'*'   ,K_ALT    ,' '   ,0         ,K_F1       ,K_F2  ,K_F3        ,K_F4       ,K_F5 ,//3
-       K_F6       ,K_F7  ,K_F8 ,K_F9 ,K_F10,K_PAUSE,0      ,K_HOME,K_UPARROW,K_PGUP,K_KP_MINUS,K_LEFTARROW,K_KP_5,K_RIGHTARROW,K_KP_PLUS  ,K_END,//4
-       K_DOWNARROW,K_PGDN,K_INS,K_DEL,0    ,0      ,0      ,K_F11 ,K_F12    ,0     ,0         ,0          ,0     ,0           ,0          ,0    ,//5
-       0          ,0     ,0    ,0    ,0    ,0      ,0      ,0     ,0        ,0     ,0         ,0          ,0     ,0           ,0          ,0    ,//6
-       0          ,0     ,0    ,0    ,0    ,0      ,0      ,0     ,0        ,0     ,0         ,0          ,0     ,0           ,0          ,0     //7
+//  0           1        2     3     4     5       6           7      8         9      A          B           C       D            E           F
+       0          ,K_ESCAPE,'1'  ,'2'  ,'3'  ,'4'    ,'5'        ,'6'   ,'7'      ,'8'   ,'9'       ,'0'        ,'-'    ,'='         ,K_BACKSPACE,K_TAB,//0
+       'q'        ,'w'     ,'e'  ,'r'  ,'t'  ,'y'    ,'u'        ,'i'   ,'o'      ,'p'   ,'['       ,']'        ,K_ENTER,K_CTRL      ,'a'        ,'s'  ,//1
+       'd'        ,'f'     ,'g'  ,'h'  ,'j'  ,'k'    ,'l'        ,';'   ,'\''     ,'`'   ,K_SHIFT   ,'\\'       ,'z'    ,'x'         ,'c'        ,'v'  ,//2
+       'b'        ,'n'     ,'m'  ,','  ,'.'  ,'/'    ,K_SHIFT    ,'*'   ,K_ALT    ,' '   ,K_CAPSLOCK,K_F1       ,K_F2   ,K_F3        ,K_F4       ,K_F5 ,//3
+       K_F6       ,K_F7    ,K_F8 ,K_F9 ,K_F10,K_PAUSE,K_SCROLLOCK,K_HOME,K_UPARROW,K_PGUP,K_KP_MINUS,K_LEFTARROW,K_KP_5 ,K_RIGHTARROW,K_KP_PLUS  ,K_END,//4
+       K_DOWNARROW,K_PGDN  ,K_INS,K_DEL,0    ,0      ,0          ,K_F11 ,K_F12    ,0     ,0         ,0          ,0      ,0           ,0          ,0    ,//5
+       0          ,0       ,0    ,0    ,0    ,0      ,0          ,0     ,0        ,0     ,0         ,0          ,0      ,0           ,0          ,0    ,//6
+       0          ,0       ,0    ,0    ,0    ,0      ,0          ,0     ,0        ,0     ,0         ,0          ,0      ,0           ,0          ,0     //7
 };
 
 
@@ -368,6 +367,9 @@ static int MapKey (int key, int virtualkey)
 
        if ( !is_extended )
        {
+               if(((GetKeyState(VK_NUMLOCK)) & 0xffff) == 0)
+                       return result;
+
                switch ( result )
                {
                case K_HOME:
@@ -396,6 +398,9 @@ static int MapKey (int key, int virtualkey)
        }
        else
        {
+               if(virtualkey == VK_NUMLOCK)
+                       return K_NUMLOCK;
+
                switch ( result )
                {
                case 0x0D:
@@ -542,7 +547,8 @@ LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM  wParam, LPARAM lParam)
        LONG    lRet = 1;
        int             fActive, fMinimized, temp;
        unsigned char state[256];
-       unsigned char asciichar[4];
+       const unsigned int UNICODE_BUFFER_LENGTH = 4;
+       WCHAR unicode[UNICODE_BUFFER_LENGTH];
        int             vkey;
        int             charlength;
        qboolean down = false;
@@ -575,14 +581,13 @@ LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM  wParam, LPARAM lParam)
                        GetKeyboardState (state);
                        // alt/ctrl/shift tend to produce funky ToAscii values,
                        // and if it's not a single character we don't know care about it
-                       charlength = ToAscii (wParam, lParam >> 16, state, (LPWORD)asciichar, 0);
-                       if (vkey == K_ALT || vkey == K_CTRL || vkey == K_SHIFT || charlength == 0)
-                               asciichar[0] = 0;
-                       else if( charlength == 2 ) {
-                               asciichar[0] = asciichar[1];
-                       }
+                       charlength = ToUnicode(wParam, lParam >> 16, state, unicode, UNICODE_BUFFER_LENGTH, 0);
+                       if(vkey == K_ALT || vkey == K_CTRL || vkey == K_SHIFT || charlength == 0)
+                               unicode[0] = 0;
+                       else if(charlength == 2)
+                               unicode[0] = unicode[1];
                        if (!VID_JoyBlockEmulatedKeys(vkey))
-                               Key_Event (vkey, asciichar[0], down);
+                               Key_Event(vkey, unicode[0], down);
                        break;
 
                case WM_SYSCHAR: