benmbrennan / mupen64plus

Automatically exported from code.google.com/p/mupen64plus
0 stars 0 forks source link

Improve keyboard mappings #220

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I have created a patch which I think would improve the keyboard mapping
feature. Basically it is now checking 'event->key.keysym.unicode' instead
of 'event->key.keysym.sym'. This makes it possible to map key that requires
a modifier.

Index: main/main.c
===================================================================
--- main/main.c (revision 1340)
+++ main/main.c (working copy)
@@ -674,13 +674,13 @@
                 savestates_select_slot( event->key.keysym.unicode - '0' );
             }
             /* check all of the configurable commands */
-            else if (event->key.keysym.sym == config_get_number("Kbd
Mapping Stop", SDLK_ESCAPE))
+            else if (event->key.keysym.unicode ==
config_get_number(kbdStop, SDLK_ESCAPE))
                 stopEmulation();
-            else if (event->key.keysym.sym == config_get_number("Kbd
Mapping Fullscreen", 0))
+            else if (event->key.keysym.unicode ==
config_get_number(kbdFullscreen, SDLK_LAST))
                 changeWindow();
-            else if (event->key.keysym.sym == config_get_number("Kbd
Mapping Save State", SDLK_F5))
+            else if (event->key.keysym.unicode ==
config_get_number(kbdSave, SDLK_F5))
                 savestates_job |= SAVESTATE;
-            else if (event->key.keysym.sym == config_get_number("Kbd
Mapping Load State", SDLK_F7))
+            else if (event->key.keysym.unicode ==
config_get_number(kbdLoad, SDLK_F7))
             {
                 savestates_job |= LOADSTATE;
                 controllerCommand(0, StopRumble);
@@ -688,38 +688,38 @@
                 controllerCommand(2, StopRumble);
                 controllerCommand(3, StopRumble);
             }
-            else if (event->key.keysym.sym == config_get_number("Kbd
Mapping Increment Slot", 0))
+            else if (event->key.keysym.unicode ==
config_get_number(kbdIncrement, 0))
                 savestates_inc_slot();
-            else if (event->key.keysym.sym == config_get_number("Kbd
Mapping Reset", SDLK_F9))
+            else if (event->key.keysym.unicode ==
config_get_number(kbdReset, SDLK_F9))
             {
                 add_interupt_event(HW2_INT, 0);  /* Hardware 2 Interrupt
immediately */
                 add_interupt_event(NMI_INT, 50000000);  /* Non maskable
Interrupt after 1/2 second */
             }
-            else if (event->key.keysym.sym == config_get_number("Kbd
Mapping Speed Down", SDLK_F10))
+            else if (event->key.keysym.unicode ==
config_get_number(kbdSpeeddown, SDLK_F10))
                 main_speeddown(5);
-            else if (event->key.keysym.sym == config_get_number("Kbd
Mapping Speed Up",SDLK_F11))
+            else if (event->key.keysym.unicode ==
config_get_number(kbdSpeedup, SDLK_F11))
                 main_speedup(5);
-            else if (event->key.keysym.sym == config_get_number("Kbd
Mapping Screenshot", SDLK_F12))
+            else if (event->key.keysym.unicode ==
config_get_number(kbdScreenshot, SDLK_F12))
                 // set flag so that screenshot will be taken at the end of
frame rendering
                 take_next_screenshot();
-            else if (event->key.keysym.sym == config_get_number("Kbd
Mapping Pause", SDLK_p))
+            else if (event->key.keysym.unicode ==
config_get_number(kbdPause, SDLK_p))
                 main_pause();
-            else if (event->key.keysym.sym == config_get_number("Kbd
Mapping Mute", SDLK_m))
+            else if (event->key.keysym.unicode ==
config_get_number(kbdMute, SDLK_m))
             {
                 volumeMute();
                 main_draw_volume_osd();
             }
-            else if (event->key.keysym.sym == config_get_number("Kbd
Mapping Increase Volume", SDLK_RIGHTBRACKET))
+            else if (event->key.keysym.unicode ==
config_get_number(kbdIncrease, SDLK_RIGHTBRACKET))
             {
                 volumeUp();
                 main_draw_volume_osd();
             }
-            else if (event->key.keysym.sym == config_get_number("Kbd
Mapping Decrease Volume", SDLK_LEFTBRACKET))
+            else if (event->key.keysym.unicode ==
config_get_number(kbdDecrease, SDLK_LEFTBRACKET))
             {
                 volumeDown();
                 main_draw_volume_osd();
             }
-            else if (event->key.keysym.sym == config_get_number("Kbd
Mapping Fast Forward", SDLK_f))
+            else if (event->key.keysym.unicode ==
config_get_number(kbdForward, SDLK_f))
             {
                 SavedSpeedFactor = l_SpeedFactor;
                 l_SpeedFactor = 250;
@@ -728,7 +728,7 @@
                 msgFF = osd_new_message(OSD_TOP_RIGHT, tr("Fast Forward"));
                 osd_message_set_static(msgFF);
             }
-            else if (event->key.keysym.sym == config_get_number("Kbd
Mapping Frame Advance", SDLK_SLASH))
+            else if (event->key.keysym.unicode ==
config_get_number(kbdAdvance, SDLK_SLASH))
                 main_advance_one();
             // pass all other keypresses to the input plugin
             else keyDown( 0, event->key.keysym.sym );
@@ -736,11 +736,11 @@
             return 0;

         case SDL_KEYUP:
-            if(event->key.keysym.sym == config_get_number("Kbd Mapping
Stop", SDLK_ESCAPE))
+            if(event->key.keysym.sym == config_get_number(kbdStop,
SDLK_ESCAPE))
             {
                 return 0;
             }
-            else if(event->key.keysym.sym == config_get_number("Kbd
Mapping Fast Forward", SDLK_f))
+            else if(event->key.keysym.unicode ==
config_get_number(kbdForward, SDLK_f))
             {
                 // cancel fast-forward
                 l_SpeedFactor = SavedSpeedFactor;
Index: main/main.h
===================================================================
--- main/main.h (revision 1340)
+++ main/main.h (working copy)
@@ -63,5 +63,24 @@
 void main_message(unsigned int console, unsigned int statusbar, unsigned
int osd, unsigned int osd_corner, const char* format, ...);
 void error_message(const char* format, ...);

+int get_keypress();
+
+static const char kbdFullscreen[]   = "Kbd Mapping Fullscreen";
+static const char kbdStop[]         = "Kbd Mapping Stop";
+static const char kbdPause[]        = "Kbd Mapping Pause";
+static const char kbdSave[]         = "Kbd Mapping Save State";
+static const char kbdLoad[]         = "Kbd Mapping Load State";
+static const char kbdIncrement[]    = "Kbd Mapping Increment Slot";
+static const char kbdReset[]        = "Kbd Mapping Reset";
+static const char kbdSpeeddown[]    = "Kbd Mapping Speed Down";
+static const char kbdSpeedup[]      = "Kbd Mapping Speed Up";
+static const char kbdScreenshot[]   = "Kbd Mapping Screenshot";
+static const char kbdMute[]         = "Kbd Mapping Mute";
+static const char kbdIncrease[]     = "Kbd Mapping Increase Volume";
+static const char kbdDecrease[]     = "Kbd Mapping Decrease Volume";
+static const char kbdForward[]      = "Kbd Mapping Fast Forward";
+static const char kbdAdvance[]      = "Kbd Mapping Frame Advance";
+static const char kbdGameshark[]    = "Kbd Mapping Gameshark";
+
 #endif /* __MAIN_H__ */

Original issue reported on code.google.com by olejl77@gmail.com on 16 Mar 2009 at 1:52

GoogleCodeExporter commented 9 years ago
Implemented in r1401. Issue can be closed.

Original comment by olejl77@gmail.com on 20 Jun 2009 at 3:37

GoogleCodeExporter commented 9 years ago
This has problems, and was reverted in r1402.  Keysyms and unicode are not
interchangeable, so setting defaults with SDLK_* values doesn't work.  
Secondly, I
don't think there are any unicode values for function keys, so they won't work. 
Finally, the unicode values only get filled in for KEYDOWN messages, not KEYUP, 
so
deactivating the fast-forward function when the user releases the key doesn't 
work.

Original comment by richard...@gmail.com on 9 Jul 2009 at 2:02