@@ -787,8 +787,8 @@ static void keycode_init(void)
787
787
788
788
if (video_driver_found) {
789
789
// Skip aliases
790
- static const char alias_str [] = " alias " ;
791
- if (strncmp (line, alias_str , sizeof (alias_str ) - 1 ) == 0 )
790
+ static const char sdl_str [] = " sdl " ;
791
+ if (strncmp (line, sdl_str , sizeof (sdl_str ) - 1 ) == 0 )
792
792
continue ;
793
793
794
794
// Read keycode
@@ -799,9 +799,9 @@ static void keycode_init(void)
799
799
break ;
800
800
} else {
801
801
// Search for SDL video driver string
802
- static const char alias_sdl_str [] = " alias SDL " ;
803
- if (strncmp (line, alias_sdl_str , sizeof (alias_sdl_str ) - 1 ) == 0 ) {
804
- char *p = line + sizeof (alias_sdl_str );
802
+ static const char sdl_str [] = " sdl " ;
803
+ if (strncmp (line, sdl_str , sizeof (sdl_str ) - 1 ) == 0 ) {
804
+ char *p = line + sizeof (sdl_str );
805
805
if (strstr (video_driver, p) == video_driver)
806
806
video_driver_found = true ;
807
807
}
@@ -1629,15 +1629,43 @@ void VideoInstallAccel(void)
1629
1629
1630
1630
1631
1631
/*
1632
- * Translate key event to Mac keycode, returns -1 if no keycode was found
1633
- * and -2 if the key was recognized as a hotkey
1632
+ * Keyboard-related utilify functions
1634
1633
*/
1635
1634
1635
+ static bool is_modifier_key (SDL_KeyboardEvent const & e)
1636
+ {
1637
+ switch (e.keysym .sym ) {
1638
+ case SDLK_NUMLOCK:
1639
+ case SDLK_CAPSLOCK:
1640
+ case SDLK_SCROLLOCK:
1641
+ case SDLK_RSHIFT:
1642
+ case SDLK_LSHIFT:
1643
+ case SDLK_RCTRL:
1644
+ case SDLK_LCTRL:
1645
+ case SDLK_RALT:
1646
+ case SDLK_LALT:
1647
+ case SDLK_RMETA:
1648
+ case SDLK_LMETA:
1649
+ case SDLK_LSUPER:
1650
+ case SDLK_RSUPER:
1651
+ case SDLK_MODE:
1652
+ case SDLK_COMPOSE:
1653
+ return true ;
1654
+ }
1655
+ return false ;
1656
+ }
1657
+
1636
1658
static bool is_ctrl_down (SDL_keysym const & ks)
1637
1659
{
1638
1660
return ctrl_down || (ks.mod & KMOD_CTRL);
1639
1661
}
1640
1662
1663
+
1664
+ /*
1665
+ * Translate key event to Mac keycode, returns -1 if no keycode was found
1666
+ * and -2 if the key was recognized as a hotkey
1667
+ */
1668
+
1641
1669
static int kc_decode (SDL_keysym const & ks, bool key_down)
1642
1670
{
1643
1671
switch (ks.sym ) {
@@ -1707,10 +1735,17 @@ static int kc_decode(SDL_keysym const & ks, bool key_down)
1707
1735
case SDLK_RCTRL: return 0x36 ;
1708
1736
case SDLK_LSHIFT: return 0x38 ;
1709
1737
case SDLK_RSHIFT: return 0x38 ;
1738
+ #if (defined(__APPLE__) && defined(__MACH__))
1739
+ case SDLK_LALT: return 0x3a ;
1740
+ case SDLK_RALT: return 0x3a ;
1741
+ case SDLK_LMETA: return 0x37 ;
1742
+ case SDLK_RMETA: return 0x37 ;
1743
+ #else
1710
1744
case SDLK_LALT: return 0x37 ;
1711
1745
case SDLK_RALT: return 0x37 ;
1712
1746
case SDLK_LMETA: return 0x3a ;
1713
1747
case SDLK_RMETA: return 0x3a ;
1748
+ #endif
1714
1749
case SDLK_MENU: return 0x32 ;
1715
1750
case SDLK_CAPSLOCK: return 0x39 ;
1716
1751
case SDLK_NUMLOCK: return 0x47 ;
@@ -1817,7 +1852,7 @@ static void handle_events(void)
1817
1852
// Keyboard
1818
1853
case SDL_KEYDOWN: {
1819
1854
int code = -1 ;
1820
- if (use_keycodes) {
1855
+ if (use_keycodes && ! is_modifier_key (event. key ) ) {
1821
1856
if (event2keycode (event.key , true ) != -2 ) // This is called to process the hotkeys
1822
1857
code = keycode_table[event.key .keysym .scancode & 0xff ];
1823
1858
} else
@@ -1845,13 +1880,22 @@ static void handle_events(void)
1845
1880
}
1846
1881
case SDL_KEYUP: {
1847
1882
int code = -1 ;
1848
- if (use_keycodes) {
1883
+ if (use_keycodes && ! is_modifier_key (event. key ) ) {
1849
1884
if (event2keycode (event.key , false ) != -2 ) // This is called to process the hotkeys
1850
1885
code = keycode_table[event.key .keysym .scancode & 0xff ];
1851
1886
} else
1852
1887
code = event2keycode (event.key , false );
1853
- if (code >= 0 && code != 0x39 ) { // Don't propagate Caps Lock releases
1854
- ADBKeyUp (code);
1888
+ if (code >= 0 ) {
1889
+ if (code == 0x39 ) { // Caps Lock released
1890
+ if (caps_on) {
1891
+ ADBKeyUp (code);
1892
+ caps_on = false ;
1893
+ } else {
1894
+ ADBKeyDown (code);
1895
+ caps_on = true ;
1896
+ }
1897
+ } else
1898
+ ADBKeyUp (code);
1855
1899
if (code == 0x36 )
1856
1900
ctrl_down = false ;
1857
1901
}
0 commit comments