/***************************************************************************************/ /* */ /* SCS editor Version 2 */ /* File : Keyboard.pkg */ /* Version : 07 août 2000 */ /* Scs Keyboard Management */ /* */ /***************************************************************************************/ /*************************************************************************************** * * - GESTION CLAVIER - * ***************************************************************************************/ typeof KeybLayoutList = Parameters ;; /* KEYBOARD CONSTANTS */ var KEYBOARD_FILEPATH = "Gui/Keyboard/" ;; var KEYBSTATE_SHIFT = 1 ;; var KEYBSTATE_CTRL = 2 ;; var KEYBSTATE_ALT = 4 ;; /* ----------------------------------------------------------------------- */ var KEYCODE_LSHIFT = 42 ;; var KEYCODE_RSHIFT = 54 ;; var KEYCODE_LCTRL = 29 ;; var KEYCODE_RCTRL = 285 ;; var KEYCODE_CAPSLOCK = 58 ;; var KEYCODE_TAB = 15 ;; var KEYCODE_BACKSPACE = 14 ;; var KEYCODE_ALTGR = 312 ;; var KEYCODE_ENTER = 28 ;; var KEYCODE_UPARROW = 328 ;; var KEYCODE_DOWNARROW = 336 ;; var KEYCODE_LARROW = 331 ;; var KEYCODE_RARROW = 333 ;; var KEYCODE_NUMLOCK = 325 ;; var KEYCODE_ESCAPE = 1 ;; var KEYCODE_PAGEUP = 329 ;; var KEYCODE_PAGEDOWN = 337 ;; var KEYCODE_INSERT = 338 ;; var KEYCODE_DELETE = 339 ;; var KEYCODE_HOME = 327 ;; var KEYCODE_END = 335 ;; var KEYCODE_SPACE = 57 ;; var KEYCODE_F1 = 59 ;; var KEYCODE_F2 = 60 ;; var KEYCODE_F3 = 61 ;; var KEYCODE_F4 = 62 ;; var KEYCODE_F5 = 63 ;; var KEYCODE_F6 = 64 ;; var KEYCODE_F7 = 65 ;; var KEYCODE_F8 = 66 ;; var KEYCODE_F9 = 67 ;; var KEYCODE_F10 = 68 ;; var KEYCODE_F11 = 87 ;; var KEYCODE_F12 = 88 ;; var KEYCODE_NUMPAD_ENTER = 284 ;; var KEYCODE_NUMPAD_ADD = 78 ;; var KEYCODE_NUMPAD_SUB = 74 ;; var KEYCODE_NUMPAD_MULT = 55 ;; var KEYCODE_NUMPAD_DIV = 309 ;; var KEYCODE_NUMPAD_1 = 79 ;; var KEYCODE_NUMPAD_2 = 80 ;; var KEYCODE_NUMPAD_3 = 81 ;; var KEYCODE_NUMPAD_4 = 75 ;; var KEYCODE_NUMPAD_5 = 76 ;; var KEYCODE_NUMPAD_6 = 77 ;; var KEYCODE_NUMPAD_7 = 71 ;; var KEYCODE_NUMPAD_8 = 72 ;; var KEYCODE_NUMPAD_9 = 73 ;; var KEYCODE_NUMPAD_0 = 82 ;; var KEYCODE_A = 16 ;; var KEYCODE_B = 48 ;; var KEYCODE_C = 46 ;; var KEYCODE_D = 32 ;; var KEYCODE_E = 18 ;; var KEYCODE_F = 33 ;; var KEYCODE_G = 34 ;; var KEYCODE_H = 35 ;; var KEYCODE_I = 23 ;; var KEYCODE_J = 36 ;; var KEYCODE_K = 37 ;; var KEYCODE_L = 38 ;; var KEYCODE_M = 39 ;; var KEYCODE_N = 49 ;; var KEYCODE_O = 24 ;; var KEYCODE_P = 25 ;; var KEYCODE_Q = 30 ;; var KEYCODE_R = 19 ;; var KEYCODE_S = 31 ;; var KEYCODE_T = 20 ;; var KEYCODE_U = 22 ;; var KEYCODE_V = 47 ;; var KEYCODE_W = 44 ;; var KEYCODE_X = 45 ;; var KEYCODE_Y = 21 ;; var KEYCODE_Z = 17 ;; var KEYCODE_1 = 2 ;; var KEYCODE_2 = 3 ;; var KEYCODE_3 = 4 ;; var KEYCODE_4 = 5 ;; var KEYCODE_5 = 6 ;; var KEYCODE_6 = 7 ;; var KEYCODE_7 = 8 ;; var KEYCODE_8 = 9 ;; var KEYCODE_9 = 10 ;; var KEYCODE_0 = 11 ;; /* --------------------------------------------------------- */ /* Keyboard management Functions */ fun KEYBOARD_IsKey(scancode,keytype) = { (scancode == keytype) ; } ;; fun KEYBOARD_GetKeyboardState() = /* Gets keyboard state */ /* Returns a bitmask which can be one or a "OR" combination of these values : - KEYBSTATE_SHIFT - KEYBSTATE_CTRL - KEYBSTATE_ALT */ { (_keybdstate&KEYBSTATE_SHIFT)| (_keybdstate&KEYBSTATE_CTRL)| (_keybdstate&KEYBSTATE_ALT) ; } ;; /* fun KEYBOARD_GetKeyLabel(scancode, state) = { let strcatn (if state&KEYBSTATE_SHIFT then "SHIFT - " else ""):: (if state&KEYBSTATE_CTRL then "CTRL - " else ""):: (if state&KEYBSTATE_ALT then "ALT - " else ""):: nil -> stxt in let if KEYBOARD_IsKey scancode KEYCODE_A then "A" else if KEYBOARD_IsKey scancode KEYCODE_B then "B" else if KEYBOARD_IsKey scancode KEYCODE_C then "C" else if KEYBOARD_IsKey scancode KEYCODE_D then "D" else if KEYBOARD_IsKey scancode KEYCODE_E then "E" else if KEYBOARD_IsKey scancode KEYCODE_F then "F" else if KEYBOARD_IsKey scancode KEYCODE_G then "G" else if KEYBOARD_IsKey scancode KEYCODE_H then "H" else if KEYBOARD_IsKey scancode KEYCODE_I then "I" else if KEYBOARD_IsKey scancode KEYCODE_J then "J" else if KEYBOARD_IsKey scancode KEYCODE_K then "K" else if KEYBOARD_IsKey scancode KEYCODE_L then "L" else if KEYBOARD_IsKey scancode KEYCODE_M then "M" else if KEYBOARD_IsKey scancode KEYCODE_N then "N" else if KEYBOARD_IsKey scancode KEYCODE_O then "O" else if KEYBOARD_IsKey scancode KEYCODE_P then "P" else if KEYBOARD_IsKey scancode KEYCODE_Q then "Q" else if KEYBOARD_IsKey scancode KEYCODE_R then "R" else if KEYBOARD_IsKey scancode KEYCODE_S then "S" else if KEYBOARD_IsKey scancode KEYCODE_T then "T" else if KEYBOARD_IsKey scancode KEYCODE_U then "U" else if KEYBOARD_IsKey scancode KEYCODE_V then "V" else if KEYBOARD_IsKey scancode KEYCODE_W then "W" else if KEYBOARD_IsKey scancode KEYCODE_X then "X" else if KEYBOARD_IsKey scancode KEYCODE_Y then "Y" else if KEYBOARD_IsKey scancode KEYCODE_Z then "Z" else if KEYBOARD_IsKey scancode KEYCODE_F1 then "F1" else if KEYBOARD_IsKey scancode KEYCODE_F2 then "F2" else if KEYBOARD_IsKey scancode KEYCODE_F3 then "F3" else if KEYBOARD_IsKey scancode KEYCODE_F4 then "F4" else if KEYBOARD_IsKey scancode KEYCODE_F5 then "F5" else if KEYBOARD_IsKey scancode KEYCODE_F6 then "F6" else if KEYBOARD_IsKey scancode KEYCODE_F7 then "F7" else if KEYBOARD_IsKey scancode KEYCODE_F8 then "F8" else if KEYBOARD_IsKey scancode KEYCODE_F9 then "F9" else if KEYBOARD_IsKey scancode KEYCODE_1 then "1" else if KEYBOARD_IsKey scancode KEYCODE_2 then "2" else if KEYBOARD_IsKey scancode KEYCODE_3 then "3" else if KEYBOARD_IsKey scancode KEYCODE_4 then "4" else if KEYBOARD_IsKey scancode KEYCODE_5 then "5" else if KEYBOARD_IsKey scancode KEYCODE_6 then "6" else if KEYBOARD_IsKey scancode KEYCODE_7 then "7" else if KEYBOARD_IsKey scancode KEYCODE_8 then "8" else if KEYBOARD_IsKey scancode KEYCODE_9 then "9" else if KEYBOARD_IsKey scancode KEYCODE_0 then "0" else if KEYBOARD_IsKey scancode KEYCODE_LSHIFT then "LSHIFT" else if KEYBOARD_IsKey scancode KEYCODE_RSHIFT then "RSHIFT" else if KEYBOARD_IsKey scancode KEYCODE_LCTRL then "LCTRL" else if KEYBOARD_IsKey scancode KEYCODE_RCTRL then "RCTRL" else if KEYBOARD_IsKey scancode KEYCODE_CAPSLOCK then "CAPSLOCK" else if KEYBOARD_IsKey scancode KEYCODE_TAB then "TAB" else if KEYBOARD_IsKey scancode KEYCODE_BACKSPACE then "BACKSPACE" else if KEYBOARD_IsKey scancode KEYCODE_ESCAPE then "ESCAPE" else if KEYBOARD_IsKey scancode KEYCODE_NUMLOCK then "NUMLOCK" else if KEYBOARD_IsKey scancode KEYCODE_ALTGR then "ALT GR" else if KEYBOARD_IsKey scancode KEYCODE_ENTER then "ENTER" else if KEYBOARD_IsKey scancode KEYCODE_SPACE then "SPACE" else if KEYBOARD_IsKey scancode KEYCODE_PAGEUP then "PAGE UP" else if KEYBOARD_IsKey scancode KEYCODE_PAGEDOWN then "PAGE DOWN" else if KEYBOARD_IsKey scancode KEYCODE_INSERT then "INSERT" else if KEYBOARD_IsKey scancode KEYCODE_DELETE then "DELETE" else if KEYBOARD_IsKey scancode KEYCODE_HOME then "HOME" else if KEYBOARD_IsKey scancode KEYCODE_END then "END" else if KEYBOARD_IsKey scancode KEYCODE_UPARROW then "UP" else if KEYBOARD_IsKey scancode KEYCODE_DOWNARROW then "DOWN" else if KEYBOARD_IsKey scancode KEYCODE_LARROW then "LEFT" else if KEYBOARD_IsKey scancode KEYCODE_RARROW then "RIGHT" else if KEYBOARD_IsKey scancode KEYCODE_NUMPAD_ENTER then "NUMPAD ENTER" else if KEYBOARD_IsKey scancode KEYCODE_NUMPAD_DIV then "NUMPAD DIV" else if KEYBOARD_IsKey scancode KEYCODE_NUMPAD_MULT then "NUMPAD MULT" else if KEYBOARD_IsKey scancode KEYCODE_NUMPAD_ADD then "NUMPAD ADD" else if KEYBOARD_IsKey scancode KEYCODE_NUMPAD_SUB then "NUMPAD SUBST" else if KEYBOARD_IsKey scancode KEYCODE_NUMPAD_1 then "NUMPAD 1" else if KEYBOARD_IsKey scancode KEYCODE_NUMPAD_2 then "NUMPAD 2" else if KEYBOARD_IsKey scancode KEYCODE_NUMPAD_3 then "NUMPAD 3" else if KEYBOARD_IsKey scancode KEYCODE_NUMPAD_4 then "NUMPAD 4" else if KEYBOARD_IsKey scancode KEYCODE_NUMPAD_5 then "NUMPAD 5" else if KEYBOARD_IsKey scancode KEYCODE_NUMPAD_6 then "NUMPAD 6" else if KEYBOARD_IsKey scancode KEYCODE_NUMPAD_7 then "NUMPAD 7" else if KEYBOARD_IsKey scancode KEYCODE_NUMPAD_8 then "NUMPAD 8" else if KEYBOARD_IsKey scancode KEYCODE_NUMPAD_9 then "NUMPAD 9" else if KEYBOARD_IsKey scancode KEYCODE_NUMPAD_0 then "NUMPAD 0" else "" -> keylabel in strcat stxt keylabel ; } ;; */ fun KEYBOARD_IsSHIFTKeyDown() = /* Returns true if SHIFT key is down */ { KEYBOARD_GetKeyboardState&KEYBSTATE_SHIFT ; } ;; fun KEYBOARD_IsCTRLKeyDown() = /* Returns true if CTRL key is down */ { KEYBOARD_GetKeyboardState&KEYBSTATE_CTRL ; } ;; fun KEYBOARD_IsALTKeyDown() = /* Returns true if ALT key is down */ { KEYBOARD_GetKeyboardState&KEYBSTATE_ALT ; } ;; fun KEYBOARD_InitLayout() = { set KEYCODE_LSHIFT = PARAMS_GetI KeybLayoutList "KEYCODE_LSHIFT" ; set KEYCODE_RSHIFT = PARAMS_GetI KeybLayoutList "KEYCODE_RSHIFT" ; set KEYCODE_LCTRL = PARAMS_GetI KeybLayoutList "KEYCODE_LCTRL" ; set KEYCODE_RCTRL = PARAMS_GetI KeybLayoutList "KEYCODE_RCTRL" ; set KEYCODE_CAPSLOCK = PARAMS_GetI KeybLayoutList "KEYCODE_CAPSLOCK" ; set KEYCODE_TAB = PARAMS_GetI KeybLayoutList "KEYCODE_TAB" ; set KEYCODE_BACKSPACE = PARAMS_GetI KeybLayoutList "KEYCODE_BACKSPACE" ; set KEYCODE_ALTGR = PARAMS_GetI KeybLayoutList "KEYCODE_ALTGR" ; set KEYCODE_ENTER = PARAMS_GetI KeybLayoutList "KEYCODE_ENTER" ; set KEYCODE_SPACE = PARAMS_GetI KeybLayoutList "KEYCODE_SPACE" ; set KEYCODE_UPARROW = PARAMS_GetI KeybLayoutList "KEYCODE_UPARROW" ; set KEYCODE_DOWNARROW = PARAMS_GetI KeybLayoutList "KEYCODE_DOWNARROW" ; set KEYCODE_LARROW = PARAMS_GetI KeybLayoutList "KEYCODE_LARROW" ; set KEYCODE_RARROW = PARAMS_GetI KeybLayoutList "KEYCODE_RARROW" ; set KEYCODE_NUMLOCK = PARAMS_GetI KeybLayoutList "KEYCODE_NUMLOCK" ; set KEYCODE_ESCAPE = PARAMS_GetI KeybLayoutList "KEYCODE_ESCAPE" ; set KEYCODE_PAGEUP = PARAMS_GetI KeybLayoutList "KEYCODE_PAGEUP" ; set KEYCODE_PAGEDOWN = PARAMS_GetI KeybLayoutList "KEYCODE_PAGEDOWN" ; set KEYCODE_INSERT = PARAMS_GetI KeybLayoutList "KEYCODE_INSERT" ; set KEYCODE_DELETE = PARAMS_GetI KeybLayoutList "KEYCODE_DELETE" ; set KEYCODE_HOME = PARAMS_GetI KeybLayoutList "KEYCODE_HOME" ; set KEYCODE_END = PARAMS_GetI KeybLayoutList "KEYCODE_END" ; set KEYCODE_F1 = PARAMS_GetI KeybLayoutList "KEYCODE_F1" ; set KEYCODE_F2 = PARAMS_GetI KeybLayoutList "KEYCODE_F2" ; set KEYCODE_F3 = PARAMS_GetI KeybLayoutList "KEYCODE_F3" ; set KEYCODE_F4 = PARAMS_GetI KeybLayoutList "KEYCODE_F4" ; set KEYCODE_F5 = PARAMS_GetI KeybLayoutList "KEYCODE_F5" ; set KEYCODE_F6 = PARAMS_GetI KeybLayoutList "KEYCODE_F6" ; set KEYCODE_F7 = PARAMS_GetI KeybLayoutList "KEYCODE_F7" ; set KEYCODE_F8 = PARAMS_GetI KeybLayoutList "KEYCODE_F8" ; set KEYCODE_F9 = PARAMS_GetI KeybLayoutList "KEYCODE_F9" ; set KEYCODE_F10 = PARAMS_GetI KeybLayoutList "KEYCODE_F10" ; set KEYCODE_F11 = PARAMS_GetI KeybLayoutList "KEYCODE_F11" ; set KEYCODE_F12 = PARAMS_GetI KeybLayoutList "KEYCODE_F12" ; set KEYCODE_NUMPAD_ENTER = PARAMS_GetI KeybLayoutList "KEYCODE_NUMPAD_ENTER" ; set KEYCODE_NUMPAD_ADD = PARAMS_GetI KeybLayoutList "KEYCODE_NUMPAD_ADD" ; set KEYCODE_NUMPAD_SUB = PARAMS_GetI KeybLayoutList "KEYCODE_NUMPAD_SUB" ; set KEYCODE_NUMPAD_MULT = PARAMS_GetI KeybLayoutList "KEYCODE_NUMPAD_MULT" ; set KEYCODE_NUMPAD_DIV = PARAMS_GetI KeybLayoutList "KEYCODE_NUMPAD_DIV" ; set KEYCODE_NUMPAD_1 = PARAMS_GetI KeybLayoutList "KEYCODE_NUMPAD_1" ; set KEYCODE_NUMPAD_2 = PARAMS_GetI KeybLayoutList "KEYCODE_NUMPAD_2" ; set KEYCODE_NUMPAD_3 = PARAMS_GetI KeybLayoutList "KEYCODE_NUMPAD_3" ; set KEYCODE_NUMPAD_4 = PARAMS_GetI KeybLayoutList "KEYCODE_NUMPAD_4" ; set KEYCODE_NUMPAD_5 = PARAMS_GetI KeybLayoutList "KEYCODE_NUMPAD_5" ; set KEYCODE_NUMPAD_6 = PARAMS_GetI KeybLayoutList "KEYCODE_NUMPAD_6" ; set KEYCODE_NUMPAD_7 = PARAMS_GetI KeybLayoutList "KEYCODE_NUMPAD_7" ; set KEYCODE_NUMPAD_8 = PARAMS_GetI KeybLayoutList "KEYCODE_NUMPAD_8" ; set KEYCODE_NUMPAD_9 = PARAMS_GetI KeybLayoutList "KEYCODE_NUMPAD_9" ; set KEYCODE_NUMPAD_0 = PARAMS_GetI KeybLayoutList "KEYCODE_NUMPAD_0" ; set KEYCODE_A = PARAMS_GetI KeybLayoutList "KEYCODE_A" ; set KEYCODE_B = PARAMS_GetI KeybLayoutList "KEYCODE_B" ; set KEYCODE_C = PARAMS_GetI KeybLayoutList "KEYCODE_C" ; set KEYCODE_D = PARAMS_GetI KeybLayoutList "KEYCODE_D" ; set KEYCODE_E = PARAMS_GetI KeybLayoutList "KEYCODE_E" ; set KEYCODE_F = PARAMS_GetI KeybLayoutList "KEYCODE_F" ; set KEYCODE_G = PARAMS_GetI KeybLayoutList "KEYCODE_G" ; set KEYCODE_H = PARAMS_GetI KeybLayoutList "KEYCODE_H" ; set KEYCODE_I = PARAMS_GetI KeybLayoutList "KEYCODE_I" ; set KEYCODE_J = PARAMS_GetI KeybLayoutList "KEYCODE_J" ; set KEYCODE_K = PARAMS_GetI KeybLayoutList "KEYCODE_K" ; set KEYCODE_L = PARAMS_GetI KeybLayoutList "KEYCODE_L" ; set KEYCODE_M = PARAMS_GetI KeybLayoutList "KEYCODE_M" ; set KEYCODE_N = PARAMS_GetI KeybLayoutList "KEYCODE_N" ; set KEYCODE_O = PARAMS_GetI KeybLayoutList "KEYCODE_O" ; set KEYCODE_P = PARAMS_GetI KeybLayoutList "KEYCODE_P" ; set KEYCODE_Q = PARAMS_GetI KeybLayoutList "KEYCODE_Q" ; set KEYCODE_R = PARAMS_GetI KeybLayoutList "KEYCODE_R" ; set KEYCODE_S = PARAMS_GetI KeybLayoutList "KEYCODE_S" ; set KEYCODE_T = PARAMS_GetI KeybLayoutList "KEYCODE_T" ; set KEYCODE_U = PARAMS_GetI KeybLayoutList "KEYCODE_U" ; set KEYCODE_V = PARAMS_GetI KeybLayoutList "KEYCODE_V" ; set KEYCODE_W = PARAMS_GetI KeybLayoutList "KEYCODE_W" ; set KEYCODE_X = PARAMS_GetI KeybLayoutList "KEYCODE_X" ; set KEYCODE_Y = PARAMS_GetI KeybLayoutList "KEYCODE_Y" ; set KEYCODE_Z = PARAMS_GetI KeybLayoutList "KEYCODE_Z" ; set KEYCODE_1 = PARAMS_GetI KeybLayoutList "KEYCODE_1" ; set KEYCODE_2 = PARAMS_GetI KeybLayoutList "KEYCODE_2" ; set KEYCODE_3 = PARAMS_GetI KeybLayoutList "KEYCODE_3" ; set KEYCODE_4 = PARAMS_GetI KeybLayoutList "KEYCODE_4" ; set KEYCODE_5 = PARAMS_GetI KeybLayoutList "KEYCODE_5" ; set KEYCODE_6 = PARAMS_GetI KeybLayoutList "KEYCODE_6" ; set KEYCODE_7 = PARAMS_GetI KeybLayoutList "KEYCODE_7" ; set KEYCODE_8 = PARAMS_GetI KeybLayoutList "KEYCODE_8" ; set KEYCODE_9 = PARAMS_GetI KeybLayoutList "KEYCODE_9" ; set KEYCODE_0 = PARAMS_GetI KeybLayoutList "KEYCODE_0" ; } ;; fun KEYBOARD_LoadKeyboardLayout(layoutcode) = /* see keyboard layout codes at top of file */ { /*_fooS strcatn "Entering KEYBOARD_LoadKeyboardLayout !: "::(itoa layoutcode)::" -"::nil ;*/ let strcatn SCS_PATH::KEYBOARD_FILEPATH::"keyblayout"::(itoa layoutcode)::".def"::nil -> sfilename in { let _getpack _checkpack sfilename -> keyfile in if keyfile == nil then { ERRORS_AddError 1 1 (strcatn "Could not load keyboard layout - File "::sfilename::nil) ; 0 ; } else { set KeybLayoutList = PARAMS_Load strextr keyfile ; KEYBOARD_InitLayout ; 0 ; } ; } ; } ;; fun KEYBOARD_Init () = { let PARAMS_GetS SCSparameters "KEYBOARD_LAYOUT" -> slayout in let PARAMS_GetI SCSparameters (strcat "KEYBOARD_LAYOUT_" slayout) -> layoutcode in KEYBOARD_LoadKeyboardLayout layoutcode ; 0 ; } ;;