{-# OPTIONS_GHC -Wall #-} {-# Language DeriveDataTypeable #-} module Key ( KeyEvent(..) , Key(..) , decodeKey ) where import Data.Typeable ( Typeable ) import Data.Data ( Data ) data KeyEvent = KeyPressed Key | KeyReleased Key deriving (Show, Eq, Ord, Data, Typeable) data Key = KC_UNASSIGNED -- = 0x00 | KC_ESCAPE -- = 0x01 | KC_1 -- = 0x02 | KC_2 -- = 0x03 | KC_3 -- = 0x04 | KC_4 -- = 0x05 | KC_5 -- = 0x06 | KC_6 -- = 0x07 | KC_7 -- = 0x08 | KC_8 -- = 0x09 | KC_9 -- = 0x0A | KC_0 -- = 0x0B | KC_MINUS -- = 0x0C -- - on main keyboard | KC_EQUALS -- = 0x0D | KC_BACK -- = 0x0E -- backspace | KC_TAB -- = 0x0F | KC_Q -- = 0x10 | KC_W -- = 0x11 | KC_E -- = 0x12 | KC_R -- = 0x13 | KC_T -- = 0x14 | KC_Y -- = 0x15 | KC_U -- = 0x16 | KC_I -- = 0x17 | KC_O -- = 0x18 | KC_P -- = 0x19 | KC_LBRACKET -- = 0x1A | KC_RBRACKET -- = 0x1B | KC_RETURN -- = 0x1C -- Enter on main keyboard | KC_LCONTROL -- = 0x1D | KC_A -- = 0x1E | KC_S -- = 0x1F | KC_D -- = 0x20 | KC_F -- = 0x21 | KC_G -- = 0x22 | KC_H -- = 0x23 | KC_J -- = 0x24 | KC_K -- = 0x25 | KC_L -- = 0x26 | KC_SEMICOLON -- = 0x27 | KC_APOSTROPHE -- = 0x28 | KC_GRAVE -- = 0x29 -- accent | KC_LSHIFT -- = 0x2A | KC_BACKSLASH -- = 0x2B | KC_Z -- = 0x2C | KC_X -- = 0x2D | KC_C -- = 0x2E | KC_V -- = 0x2F | KC_B -- = 0x30 | KC_N -- = 0x31 | KC_M -- = 0x32 | KC_COMMA -- = 0x33 | KC_PERIOD -- = 0x34 -- . on main keyboard | KC_SLASH -- = 0x35 -- / on main keyboard | KC_RSHIFT -- = 0x36 | KC_MULTIPLY -- = 0x37 -- * on numeric keypad | KC_LMENU -- = 0x38 -- left Alt | KC_SPACE -- = 0x39 | KC_CAPITAL -- = 0x3A | KC_F1 -- = 0x3B | KC_F2 -- = 0x3C | KC_F3 -- = 0x3D | KC_F4 -- = 0x3E | KC_F5 -- = 0x3F | KC_F6 -- = 0x40 | KC_F7 -- = 0x41 | KC_F8 -- = 0x42 | KC_F9 -- = 0x43 | KC_F10 -- = 0x44 | KC_NUMLOCK -- = 0x45 | KC_SCROLL -- = 0x46 -- Scroll Lock | KC_NUMPAD7 -- = 0x47 | KC_NUMPAD8 -- = 0x48 | KC_NUMPAD9 -- = 0x49 | KC_SUBTRACT -- = 0x4A -- - on numeric keypad | KC_NUMPAD4 -- = 0x4B | KC_NUMPAD5 -- = 0x4C | KC_NUMPAD6 -- = 0x4D | KC_ADD -- = 0x4E -- + on numeric keypad | KC_NUMPAD1 -- = 0x4F | KC_NUMPAD2 -- = 0x50 | KC_NUMPAD3 -- = 0x51 | KC_NUMPAD0 -- = 0x52 | KC_DECIMAL -- = 0x53 -- . on numeric keypad | KC_OEM_102 -- = 0x56 -- < > | on UK/Germany keyboards | KC_F11 -- = 0x57 | KC_F12 -- = 0x58 | KC_F13 -- = 0x64 -- (NEC PC98) | KC_F14 -- = 0x65 -- (NEC PC98) | KC_F15 -- = 0x66 -- (NEC PC98) | KC_KANA -- = 0x70 -- (Japanese keyboard) | KC_ABNT_C1 -- = 0x73 -- / ? on Portugese (Brazilian) keyboards | KC_CONVERT -- = 0x79 -- (Japanese keyboard) | KC_NOCONVERT -- = 0x7B -- (Japanese keyboard) | KC_YEN -- = 0x7D -- (Japanese keyboard) | KC_ABNT_C2 -- = 0x7E -- Numpad . on Portugese (Brazilian) keyboards | KC_NUMPADEQUALS -- = 0x8D -- = on numeric keypad (NEC PC98) | KC_PREVTRACK -- = 0x90 -- Previous Track (KC_CIRCUMFLEX on Japanese keyboard) | KC_AT -- = 0x91 -- (NEC PC98) | KC_COLON -- = 0x92 -- (NEC PC98) | KC_UNDERLINE -- = 0x93 -- (NEC PC98) | KC_KANJI -- = 0x94 -- (Japanese keyboard) | KC_STOP -- = 0x95 -- (NEC PC98) | KC_AX -- = 0x96 -- (Japan AX) | KC_UNLABELED -- = 0x97 -- (J3100) | KC_NEXTTRACK -- = 0x99 -- Next Track | KC_NUMPADENTER -- = 0x9C -- Enter on numeric keypad | KC_RCONTROL -- = 0x9D | KC_MUTE -- = 0xA0 -- Mute | KC_CALCULATOR -- = 0xA1 -- Calculator | KC_PLAYPAUSE -- = 0xA2 -- Play / Pause | KC_MEDIASTOP -- = 0xA4 -- Media Stop | KC_VOLUMEDOWN -- = 0xAE -- Volume - | KC_VOLUMEUP -- = 0xB0 -- Volume + | KC_WEBHOME -- = 0xB2 -- Web home | KC_NUMPADCOMMA -- = 0xB3 -- , on numeric keypad (NEC PC98) | KC_DIVIDE -- = 0xB5 -- / on numeric keypad | KC_SYSRQ -- = 0xB7 | KC_RMENU -- = 0xB8 -- right Alt | KC_PAUSE -- = 0xC5 -- Pause | KC_HOME -- = 0xC7 -- Home on arrow keypad | KC_UP -- = 0xC8 -- UpArrow on arrow keypad | KC_PGUP -- = 0xC9 -- PgUp on arrow keypad | KC_LEFT -- = 0xCB -- LeftArrow on arrow keypad | KC_RIGHT -- = 0xCD -- RightArrow on arrow keypad | KC_END -- = 0xCF -- End on arrow keypad | KC_DOWN -- = 0xD0 -- DownArrow on arrow keypad | KC_PGDOWN -- = 0xD1 -- PgDn on arrow keypad | KC_INSERT -- = 0xD2 -- Insert on arrow keypad | KC_DELETE -- = 0xD3 -- Delete on arrow keypad | KC_LWIN -- = 0xDB -- Left Windows key | KC_RWIN -- = 0xDC -- Right Windows key | KC_APPS -- = 0xDD -- AppMenu key | KC_POWER -- = 0xDE -- System Power | KC_SLEEP -- = 0xDF -- System Sleep | KC_WAKE -- = 0xE3 -- System Wake | KC_WEBSEARCH -- = 0xE5 -- Web Search | KC_WEBFAVORITES -- = 0xE6 -- Web Favorites | KC_WEBREFRESH -- = 0xE7 -- Web Refresh | KC_WEBSTOP -- = 0xE8 -- Web Stop | KC_WEBFORWARD -- = 0xE9 -- Web Forward | KC_WEBBACK -- = 0xEA -- Web Back | KC_MYCOMPUTER -- = 0xEB -- My Computer | KC_MAIL -- = 0xEC -- Mail | KC_MEDIASELECT -- = 0xED -- Media Select deriving (Show, Eq, Ord, Data, Typeable) decodeKey :: Int -> Key decodeKey 0 = KC_UNASSIGNED decodeKey 1 = KC_ESCAPE decodeKey 2 = KC_1 decodeKey 3 = KC_2 decodeKey 4 = KC_3 decodeKey 5 = KC_4 decodeKey 6 = KC_5 decodeKey 7 = KC_6 decodeKey 8 = KC_7 decodeKey 9 = KC_8 decodeKey 10 = KC_9 decodeKey 11 = KC_0 decodeKey 12 = KC_MINUS decodeKey 13 = KC_EQUALS decodeKey 14 = KC_BACK decodeKey 15 = KC_TAB decodeKey 16 = KC_Q decodeKey 17 = KC_W decodeKey 18 = KC_E decodeKey 19 = KC_R decodeKey 20 = KC_T decodeKey 21 = KC_Y decodeKey 22 = KC_U decodeKey 23 = KC_I decodeKey 24 = KC_O decodeKey 25 = KC_P decodeKey 26 = KC_LBRACKET decodeKey 27 = KC_RBRACKET decodeKey 28 = KC_RETURN decodeKey 29 = KC_LCONTROL decodeKey 30 = KC_A decodeKey 31 = KC_S decodeKey 32 = KC_D decodeKey 33 = KC_F decodeKey 34 = KC_G decodeKey 35 = KC_H decodeKey 36 = KC_J decodeKey 37 = KC_K decodeKey 38 = KC_L decodeKey 39 = KC_SEMICOLON decodeKey 40 = KC_APOSTROPHE decodeKey 41 = KC_GRAVE decodeKey 42 = KC_LSHIFT decodeKey 43 = KC_BACKSLASH decodeKey 44 = KC_Z decodeKey 45 = KC_X decodeKey 46 = KC_C decodeKey 47 = KC_V decodeKey 48 = KC_B decodeKey 49 = KC_N decodeKey 50 = KC_M decodeKey 51 = KC_COMMA decodeKey 52 = KC_PERIOD decodeKey 53 = KC_SLASH decodeKey 54 = KC_RSHIFT decodeKey 55 = KC_MULTIPLY decodeKey 56 = KC_LMENU decodeKey 57 = KC_SPACE decodeKey 58 = KC_CAPITAL decodeKey 59 = KC_F1 decodeKey 60 = KC_F2 decodeKey 61 = KC_F3 decodeKey 62 = KC_F4 decodeKey 63 = KC_F5 decodeKey 64 = KC_F6 decodeKey 65 = KC_F7 decodeKey 66 = KC_F8 decodeKey 67 = KC_F9 decodeKey 68 = KC_F10 decodeKey 69 = KC_NUMLOCK decodeKey 70 = KC_SCROLL decodeKey 71 = KC_NUMPAD7 decodeKey 72 = KC_NUMPAD8 decodeKey 73 = KC_NUMPAD9 decodeKey 74 = KC_SUBTRACT decodeKey 75 = KC_NUMPAD4 decodeKey 76 = KC_NUMPAD5 decodeKey 77 = KC_NUMPAD6 decodeKey 78 = KC_ADD decodeKey 79 = KC_NUMPAD1 decodeKey 80 = KC_NUMPAD2 decodeKey 81 = KC_NUMPAD3 decodeKey 82 = KC_NUMPAD0 decodeKey 83 = KC_DECIMAL decodeKey 86 = KC_OEM_102 decodeKey 87 = KC_F11 decodeKey 88 = KC_F12 decodeKey 100 = KC_F13 decodeKey 101 = KC_F14 decodeKey 102 = KC_F15 decodeKey 112 = KC_KANA decodeKey 115 = KC_ABNT_C1 decodeKey 121 = KC_CONVERT decodeKey 123 = KC_NOCONVERT decodeKey 125 = KC_YEN decodeKey 126 = KC_ABNT_C2 decodeKey 141 = KC_NUMPADEQUALS decodeKey 144 = KC_PREVTRACK decodeKey 145 = KC_AT decodeKey 146 = KC_COLON decodeKey 147 = KC_UNDERLINE decodeKey 148 = KC_KANJI decodeKey 149 = KC_STOP decodeKey 150 = KC_AX decodeKey 151 = KC_UNLABELED decodeKey 153 = KC_NEXTTRACK decodeKey 156 = KC_NUMPADENTER decodeKey 157 = KC_RCONTROL decodeKey 160 = KC_MUTE decodeKey 161 = KC_CALCULATOR decodeKey 162 = KC_PLAYPAUSE decodeKey 164 = KC_MEDIASTOP decodeKey 174 = KC_VOLUMEDOWN decodeKey 176 = KC_VOLUMEUP decodeKey 178 = KC_WEBHOME decodeKey 179 = KC_NUMPADCOMMA decodeKey 181 = KC_DIVIDE decodeKey 183 = KC_SYSRQ decodeKey 184 = KC_RMENU decodeKey 197 = KC_PAUSE decodeKey 199 = KC_HOME decodeKey 200 = KC_UP decodeKey 201 = KC_PGUP decodeKey 203 = KC_LEFT decodeKey 205 = KC_RIGHT decodeKey 207 = KC_END decodeKey 208 = KC_DOWN decodeKey 209 = KC_PGDOWN decodeKey 210 = KC_INSERT decodeKey 211 = KC_DELETE decodeKey 219 = KC_LWIN decodeKey 220 = KC_RWIN decodeKey 221 = KC_APPS decodeKey 222 = KC_POWER decodeKey 223 = KC_SLEEP decodeKey 227 = KC_WAKE decodeKey 229 = KC_WEBSEARCH decodeKey 230 = KC_WEBFAVORITES decodeKey 231 = KC_WEBREFRESH decodeKey 232 = KC_WEBSTOP decodeKey 233 = KC_WEBFORWARD decodeKey 234 = KC_WEBBACK decodeKey 235 = KC_MYCOMPUTER decodeKey 236 = KC_MAIL decodeKey 237 = KC_MEDIASELECT decodeKey n = error $ "decodeKey got unmatched int: " ++ show n