]> git.tdb.fi Git - libs/gui.git/blobdiff - source/input/keys.cpp
Drop Id tags and copyright notices from files
[libs/gui.git] / source / input / keys.cpp
index d7de3b1b326ae007168a4ca324edda30d66356f3..37a376aaa6c662eb391aaa4704148f5adcb8e8dd 100644 (file)
@@ -1,12 +1,8 @@
-/* $Id$
-
-This file is part of libmspgbase
-Copyright © 2007 Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
 #include <map>
-#ifndef WIN32
+#ifdef WIN32
+#include <windows.h>
+#else
+#include <X11/X.h>
 #include <X11/keysym.h>
 #endif
 #include <msp/core/except.h>
@@ -101,6 +97,15 @@ unsigned keymap[Msp::Input::N_KEYS_]=
 #endif
 };
 
+unsigned modmap[Msp::Input::N_MODS_]=
+{
+#ifndef WIN32
+       ShiftMask, ControlMask, Mod1Mask, Mod4Mask
+#else
+       1, 2, 4, 8
+#endif
+};
+
 }
 
 namespace Msp {
@@ -129,10 +134,19 @@ unsigned key_from_sys(unsigned code)
 
 unsigned key_to_sys(unsigned key)
 {
-       if(key>N_KEYS_)
+       if(key>=N_KEYS_)
                throw InvalidParameterValue("Key out of range");
        return keymap[key];
 }
 
+unsigned mod_from_sys(unsigned mod)
+{
+       unsigned result = 0;
+       for(unsigned i=0; i<N_MODS_; ++i)
+               if(mod&modmap[i])
+                       result|=1<<i;
+       return result;
+}
+
 } // namespace Input
 } // namespace Msp