Advertisement
deadelf79

[RGSS 1] Keyboard Module

Oct 2nd, 2014
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 9.48 KB | None | 0 0
  1. =begin
  2. --------------------------------------------------------------------------------
  3.               Keyboard Module
  4. --------------------------------------------------------------------------------
  5. created by Fomar0153
  6. modified by DeadElf79
  7. Версия 1.1
  8. --------------------------------------------------------------------------------
  9. Добавил все кнопки из какого-то другого скрипта.
  10. Данный модуль не требует обновления (метода update) для своей работы (в отличие
  11. от множества других).
  12. --------------------------------------------------------------------------------
  13. Инструкция:
  14.  - trigger? чтобы проверить, нажата ли клавиша
  15.  - press? чтобы проверить, зажата ли клавиша (долгое нажатие)
  16.  - toggle? для кнопок-переключателей (типа Caps lock)
  17. --------------------------------------------------------------------------------
  18. =end
  19. module Keyboard
  20.   #--------------------------------------------------------------------------
  21.   # * WINAPI
  22.   #--------------------------------------------------------------------------
  23.   KEY_STATE = Win32API.new("user32", "GetKeyState", ["i"], "i")
  24.   AKEY_STATE = Win32API.new("user32", "GetAsyncKeyState", ["i"], "i")
  25.   #--------------------------------------------------------------------------
  26.   # * Miscellaneous Keys
  27.   #--------------------------------------------------------------------------
  28.   CANCEL = 0x03 # Control-Break Processing
  29.   BACKSPACE = 0x08 # Backspace Key
  30.   TAB = 0x09 # Tab Key
  31.   CLEAR = 0x0C # Clear Key
  32.   RETURN = 0x0D # Enter Key
  33.   SHIFT = 0x10 # Shift Key
  34.   CONTROL = 0x11 # Ctrl Key
  35.   MENU = 0x12 # Alt Key
  36.   PAUSE = 0x13 # Pause Key
  37.   ESCAPE = 0x1B # Esc Key
  38.   CONVERT = 0x1C # IME Convert Key
  39.   NONCONVERT = 0x1D # IME Nonconvert Key
  40.   ACCEPT = 0x1E # IME Accept Key
  41.   SPACE = 0x20 # Space Bar Key (Space, usually blank)
  42.   PRIOR = 0x21 # Page Up Key
  43.   NEXT = 0x22 # Page Down Key
  44.   ENDS = 0x23 # End Key
  45.   HOME = 0x24 # Home Key
  46.   LEFT = 0x25 # Left Arrow Key
  47.   UP = 0x26 # Up Arrow Key
  48.   RIGHT = 0x27 # Right Arrow Key
  49.   DOWN = 0x28 # Down Arrow Key
  50.   SELECT = 0x29 # Select Key
  51.   PRINT = 0x2A # Print Key
  52.   EXECUTE = 0x2B # Execute Key
  53.   SNAPSHOT = 0x2C # Print Screen Key
  54.   DELETE = 0x2E # Delete Key
  55.   HELP = 0x2F # Help Key
  56.   LSHIFT = 0xA0 # Left Shift Key
  57.   RSHIFT = 0xA1 # Right Shift Key
  58.   LCONTROL = 0xA2 # Left Control Key (Ctrl)
  59.   RCONTROL = 0xA3 # Right Control Key (Ctrl)
  60.   LMENU = 0xA4 # Left Menu Key (Alt)
  61.   RMENU = 0xA5 # Right Menu Key (Alt)
  62.   PACKET = 0xE7 # Used to Pass Unicode Characters as Keystrokes
  63.   #--------------------------------------------------------------------------
  64.   # * Number Keys
  65.   #--------------------------------------------------------------------------
  66.   N0 = 0x30 # 0 Key
  67.   N1 = 0x31 # 1 Key
  68.   N2 = 0x32 # 2 Key
  69.   N3 = 0x33 # 3 Key
  70.   N4 = 0x34 # 4 Key
  71.   N5 = 0x35 # 5 Key
  72.   N6 = 0x36 # 6 Key
  73.   N7 = 0x37 # 7 Key
  74.   N8 = 0x38 # 8 Key
  75.   N9 = 0x39 # 9 Key
  76.   #--------------------------------------------------------------------------
  77.   # * Letter Keys
  78.   #--------------------------------------------------------------------------
  79.   A = 0x41 # A Key
  80.   B = 0x42 # B Key
  81.   C = 0x43 # C Key
  82.   D = 0x44 # D Key
  83.   E = 0x45 # E Key
  84.   F = 0x46 # F Key
  85.   G = 0x47 # G Key
  86.   H = 0x48 # H Key
  87.   I = 0x49 # I Key
  88.   J = 0x4A # J Key
  89.   K = 0x4B # K Key
  90.   L = 0x4C # L Key
  91.   M = 0x4D # M Key
  92.   N = 0x4E # N Key
  93.   O = 0x4F # O Key
  94.   P = 0x50 # P Key
  95.   Q = 0x51 # Q Key
  96.   R = 0x52 # R Key
  97.   S = 0x53 # S Key
  98.   T = 0x54 # T Key
  99.   U = 0x55 # U Key
  100.   V = 0x56 # V Key
  101.   W = 0x57 # W Key
  102.   X = 0x58 # X Key
  103.   Y = 0x59 # Y Key
  104.   Z = 0x5A # Z Key
  105.   #--------------------------------------------------------------------------
  106.   # * Windows Keys
  107.   #--------------------------------------------------------------------------
  108.   LWIN = 0x5B # Left Windows Key (Natural keyboard)
  109.   RWIN = 0x5C # Right Windows Key (Natural Keyboard)
  110.   APPS = 0x5D # Applications Key (Natural keyboard)
  111.   SLEEP = 0x5F # Computer Sleep Key
  112.   BROWSER_BACK = 0xA6 # Browser Back Key
  113.   BROWSER_FORWARD = 0xA7 # Browser Forward Key
  114.   BROWSER_REFRESH = 0xA8 # Browser Refresh Key
  115.   BROWSER_STOP = 0xA9 # Browser Stop Key
  116.   BROWSER_SEARCH = 0xAA # Browser Search Key
  117.   BROWSER_FAVORITES = 0xAB # Browser Favorites Key
  118.   BROWSER_HOME = 0xAC # Browser Start and Home Key
  119.   VOLUME_MUTE = 0xAD # Volume Mute Key
  120.   VOLUME_DOWN = 0xAE # Volume Down Key
  121.   VOLUME_UP = 0xAF # Volume Up Key
  122.   MEDIA_NEXT_TRACK = 0xB0 # Next Track Key
  123.   MEDIA_PREV_TRACK = 0xB1 # Previous Track Key
  124.   MEDIA_STOP = 0xB2 # Stop Media Key
  125.   MEDIA_PLAY_PAUSE = 0xB3 # Play/Pause Media Key
  126.   LAUNCH_MAIL = 0xB4 # Start Mail Key
  127.   LAUNCH_MEDIA_SELECT = 0xB5 # Select Media Key
  128.   LAUNCH_APP1 = 0xB6 # Start Application 1 Key
  129.   LAUNCH_APP2 = 0xB7 # Start Application 2 Key
  130.   PROCESSKEY = 0xE5 # IME Process Key
  131.   ATTN = 0xF6 # Attn Key
  132.   CRSEL = 0xF7 # CrSel Key
  133.   EXSEL = 0xF8 # ExSel Key
  134.   EREOF = 0xF9 # Erase EOF Key
  135.   PLAY = 0xFA # Play Key
  136.   ZOOM = 0xFB # Zoom Key
  137.   PA1 = 0xFD # PA1 Key
  138.   #--------------------------------------------------------------------------
  139.   # * Number Pad Keys
  140.   #--------------------------------------------------------------------------
  141.   NUMPAD0 = 0x60 # Numeric Keypad 0 Key
  142.   NUMPAD1 = 0x61 # Numeric Keypad 1 Key
  143.   NUMPAD2 = 0x62 # Numeric Keypad 2 Key
  144.   NUMPAD3 = 0x63 # Numeric Keypad 3 Key
  145.   NUMPAD4 = 0x64 # Numeric Keypad 4 Key
  146.   NUMPAD5 = 0x65 # Numeric Keypad 5 Key
  147.   NUMPAD6 = 0x66 # Numeric Keypad 6 Key
  148.   NUMPAD7 = 0x67 # Numeric Keypad 7 Key
  149.   NUMPAD8 = 0x68 # Numeric Keypad 8 Key
  150.   NUMPAD9 = 0x69 # Numeric Keypad 9 Key
  151.   MULTIPLY = 0x6A # Multiply Key (*)
  152.   ADD = 0x6B # Add Key (+)
  153.   SEPARATOR = 0x6C # Separator Key
  154.   SUBTRACT = 0x6D # Subtract Key (-)
  155.   DECIMAL = 0x6E # Decimal Key (.)
  156.   DIVIDE = 0x6F # Divide Key (/)
  157.   #--------------------------------------------------------------------------
  158.   # * Function Keys
  159.   #--------------------------------------------------------------------------
  160.   F1 = 0x70 # F1 Key
  161.   F2 = 0x71 # F2 Key
  162.   F3 = 0x72 # F3 Key
  163.   F4 = 0x73 # F4 Key
  164.   F5 = 0x74 # F5 Key
  165.   F6 = 0x75 # F6 Key
  166.   F7 = 0x76 # F7 Key
  167.   F8 = 0x77 # F8 Key
  168.   F9 = 0x78 # F9 Key
  169.   F10 = 0x79 # F10 Key
  170.   F11 = 0x7A # F11 Key
  171.   F12 = 0x7B # F12 Key
  172.   F13 = 0x7C # F13 Key
  173.   F14 = 0x7D # F14 Key
  174.   F15 = 0x7E # F15 Key
  175.   F16 = 0x7F # F16 Key
  176.   F17 = 0x80 # F17 Key
  177.   F18 = 0x81 # F18 Key
  178.   F19 = 0x82 # F19 Key
  179.   F20 = 0x83 # F20 Key
  180.   F21 = 0x84 # F21 Key
  181.   F22 = 0x85 # F22 Key
  182.   F23 = 0x86 # F23 Key
  183.   F24 = 0x87 # F24 Key
  184.   #--------------------------------------------------------------------------
  185.   # * Toggle Keys
  186.   #--------------------------------------------------------------------------
  187.   CAPITAL = 0x14 # Caps Lock Key
  188.   KANA = 0x15 # IME Kana Mode Key
  189.   HANGUL = 0x15 # IME Hangul Mode Key
  190.   JUNJA = 0x17 # IME Junja Mode Key
  191.   FINAL = 0x18 # IME Final Mode Key
  192.   HANJA = 0x19 # IME Hanja Mode Key
  193.   KANJI = 0x19 # IME Kanji Mode Key
  194.   MODECHANGE = 0x1F # IME Mode Change Request Key
  195.   INSERT = 0x2D # Insert Key
  196.   NUMLOCK = 0x90 # Num Lock Key
  197.   SCROLL = 0x91 # Scroll Lock Key
  198.   #--------------------------------------------------------------------------
  199.   # * OEM Keys (Vary by keyboard)
  200.   #--------------------------------------------------------------------------
  201.   OEM_1 = 0xBA # Misc Characters (; : in USA 101/102 Keyboards)
  202.   OEM_PLUS = 0xBB # + = Key
  203.   OEM_COMMA = 0xBC # , < Key
  204.   OEM_MINUS = 0xBD # - _ Key
  205.   OEM_PERIOD = 0xBE # . > Key
  206.   OEM_2 = 0xBF # Misc Characters (/ ? in USA 101/102 Keyboards)
  207.   OEM_3 = 0xC0 # Misc Characters (` ~ in USA 101/102 Keyboards)
  208.   OEM_4 = 0xDB # Misc Characters ([ { in USA 101/102 Keyboards)
  209.   OEM_5 = 0xDC # Misc Characters (\ | in USA 101/102 Keyboards)
  210.   OEM_6 = 0xDD # Misc Characters (] } in USA 101/102 Keyboards)
  211.   OEM_7 = 0xDE # Misc Characters (' " in USA 101/102 Keyboards)
  212.   OEM_8 = 0xDF # Misc Characters (Varies by Keyboard)
  213.   OEM_9 = 0xE1 # OEM Specific
  214.   OEM_10 = 0x92 # OEM Specific
  215.   OEM_11 = 0x93 # OEM Specific
  216.   OEM_12 = 0x94 # OEM Specific
  217.   OEM_13 = 0x95 # OEM Specific
  218.   OEM_14 = 0x96 # OEM Specific
  219.   OEM_15 = 0xE3 # OEM Specific
  220.   OEM_16 = 0xE4 # OEM Specific
  221.   OEM_17 = 0xE6 # OEM Specific
  222.   OEM_18 = 0xE9 # OEM Specific
  223.   OEM_19 = 0xEA # OEM Specific
  224.   OEM_20 = 0xEB # OEM Specific
  225.   OEM_21 = 0xEC # OEM Specific
  226.   OEM_22 = 0xED # OEM Specific
  227.   OEM_23 = 0xEE # OEM Specific
  228.   OEM_24 = 0xEF # OEM Specific
  229.   OEM_25 = 0xF1 # OEM Specific
  230.   OEM_26 = 0xF2 # OEM Specific
  231.   OEM_27 = 0xF3 # OEM Specific
  232.   OEM_28 = 0xF4 # OEM Specific
  233.   OEM_29 = 0xF5 # OEM Specific
  234.   OEM_102 = 0xE2 # Angle Bracket or Backslash on RT-102 Keyboards
  235.   OEM_CLEAR = 0xFE # Clear Key
  236.   #--------------------------------------------------------------------------
  237.   # * Special Keys
  238.   #--------------------------------------------------------------------------
  239.   ANYKEY = 0x100 # Any Key
  240.   #--------------------------------------------------------------------------
  241.   # * METHODS
  242.   #--------------------------------------------------------------------------
  243.   def self.trigger?(key)
  244.     if AKEY_STATE.call(key) != 0
  245.       return true
  246.     end
  247.   end
  248.  
  249.   def self.press?(key)
  250.     r = KEY_STATE.call(key)
  251.     if r == -127 or r == -128
  252.       return true
  253.     end
  254.   end
  255.  
  256.   # For things like caps lock
  257.   def self.toggle?(key)
  258.     if  KEY_STATE.call(key) == 1
  259.       return true
  260.     end
  261.   end
  262. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement