Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Keyboard Input Module (Cybersam's) Problems

Alright, my problem this time is a little weird... I implanted Cybersam's KIM and did the necessary scripting to make it work, but there seem to be a couple of keys that won't work. These are the following:

Q W Z A S D Y X C V B

Well, more or less surprisingly, those are the keys used by RMXP's INPUT:: command.

I wonder how I could get them to work, because I need all of them... I tried setting the keys to nil in the F1 menu, but they didn't work after that, neither. I wonder if there's a newer version of the KIM that fixes that error... here's the one I got:

Code:
module Kboard
  #--------------------------------------------------------------------------
  $Rmouse_BUTTON_L = 0x01        # left mouse button
  $Rmouse_BUTTON_R = 0x02        # right mouse button
  $Rmouse_BUTTON_M = 0x04        # middle mouse button
  $Rmouse_BUTTON_4 = 0x05        # 4th mouse button
  $Rmouse_BUTTON_5 = 0x06        # 5th mouse button
  #--------------------------------------------------------------------------
  $R_Key_BACK      = 0x08        # BACKSPACE key
  $R_Key_TAB       = 0x09        # TAB key
  $R_Key_RETURN    = 0x0D        # ENTER key
  $R_Key_SHIFT     = 0x10        # SHIFT key
  $R_Key_CTLR      = 0x11        # CTLR key
  $R_Key_ALT       = 0x12        # ALT key
  $R_Key_PAUSE     = 0x13        # PAUSE key
  $R_Key_CAPITAL   = 0x14        # CAPS LOCK key
  $R_Key_ESCAPE    = 0x1B        # ESC key
  $R_Key_SPACE     = 0x20        # SPACEBAR
  $R_Key_PRIOR     = 0x21        # PAGE UP key
  $R_Key_NEXT      = 0x22        # PAGE DOWN key
  $R_Key_END       = 0x23        # END key
  $R_Key_HOME      = 0x24        # HOME key
  $R_Key_LEFT      = 0x25        # LEFT ARROW key
  $R_Key_UP        = 0x26        # UP ARROW key
  $R_Key_RIGHT     = 0x27        # RIGHT ARROW key
  $R_Key_DOWN      = 0x28        # DOWN ARROW key
  $R_Key_SELECT    = 0x29        # SELECT key
  $R_Key_PRINT     = 0x2A        # PRINT key
  $R_Key_SNAPSHOT  = 0x2C        # PRINT SCREEN key
  $R_Key_INSERT    = 0x2D        # INS key
  $R_Key_DELETE    = 0x2E        # DEL key
  #--------------------------------------------------------------------------
  $R_Key_0         = 0x30        # 0 key
  $R_Key_1         = 0x31        # 1 key
  $R_Key_2         = 0x32        # 2 key
  $R_Key_3         = 0x33        # 3 key
  $R_Key_4         = 0x34        # 4 key
  $R_Key_5         = 0x35        # 5 key
  $R_Key_6         = 0x36        # 6 key
  $R_Key_7         = 0x37        # 7 key
  $R_Key_8         = 0x38        # 8 key
  $R_Key_9         = 0x39        # 9 key
  #--------------------------------------------------------------------------
  $R_Key_A         = 0x41        # A key
  $R_Key_B         = 0x42        # B key
  $R_Key_C         = 0x43        # C key
  $R_Key_D         = 0x44        # D key
  $R_Key_E         = 0x45        # E key
  $R_Key_F         = 0x46        # F key
  $R_Key_G         = 0x47        # G key
  $R_Key_H         = 0x48        # H key
  $R_Key_I         = 0x49        # I key
  $R_Key_J         = 0x4A        # J key
  $R_Key_K         = 0x4B        # K key
  $R_Key_L         = 0x4C        # L key
  $R_Key_M         = 0x4D        # M key
  $R_Key_N         = 0x4E        # N key
  $R_Key_O         = 0x4F        # O key
  $R_Key_P         = 0x50        # P key
  $R_Key_Q         = 0x51        # Q key
  $R_Key_R         = 0x52        # R key
  $R_Key_S         = 0x53        # S key
  $R_Key_T         = 0x54        # T key
  $R_Key_U         = 0x55        # U key
  $R_Key_V         = 0x56        # V key
  $R_Key_W         = 0x57        # W key
  $R_Key_X         = 0x58        # X key
  $R_Key_Y         = 0x59        # Y key
  $R_Key_Z         = 0x5A        # Z key
  #--------------------------------------------------------------------------
  $R_Key_LWIN      = 0x5B        # Left Windows key (Natural keyboard)
  $R_Key_RWIN      = 0x5C        # Right Windows key (Natural keyboard)
  $R_Key_APPS      = 0x5D        # Applications key (Natural keyboard)
  #--------------------------------------------------------------------------
  $R_Key_NUMPAD0   = 0x60        # Numeric keypad 0 key
  $R_Key_NUMPAD1   = 0x61        # Numeric keypad 1 key
  $R_Key_NUMPAD2   = 0x62        # Numeric keypad 2 key
  $R_Key_NUMPAD3   = 0x63        # Numeric keypad 3 key
  $R_Key_NUMPAD4   = 0x64        # Numeric keypad 4 key
  $R_Key_NUMPAD5   = 0x65        # Numeric keypad 5 key
  $R_Key_NUMPAD6   = 0x66        # Numeric keypad 6 key
  $R_Key_NUMPAD7   = 0x67        # Numeric keypad 7 key
  $R_Key_NUMPAD8   = 0x68        # Numeric keypad 8 key
  $R_Key_NUMPAD9   = 0x69        # Numeric keypad 9 key
  $R_Key_MULTIPLY  = 0x6A        # Multiply key (*)
  $R_Key_ADD       = 0x6B        # Add key (+)
  $R_Key_SEPARATOR = 0x6C        # Separator key
  $R_Key_SUBTRACT  = 0x6D        # Subtract key (-)
  $R_Key_DECIMAL   = 0x6E        # Decimal key
  $R_Key_DIVIDE    = 0x6F        # Divide key (/)
  #--------------------------------------------------------------------------
  $R_Key_F1        = 0x70        # F1 key
  $R_Key_F2        = 0x71        # F2 key
  $R_Key_F3        = 0x72        # F3 key
  $R_Key_F4        = 0x73        # F4 key
  $R_Key_F5        = 0x74        # F5 key
  $R_Key_F6        = 0x75        # F6 key
  $R_Key_F7        = 0x76        # F7 key
  $R_Key_F8        = 0x77        # F8 key
  $R_Key_F9        = 0x78        # F9 key
  $R_Key_F10       = 0x79        # F10 key
  $R_Key_F11       = 0x7A        # F11 key
  $R_Key_F12       = 0x7B        # F12 key
  #--------------------------------------------------------------------------
  $R_Key_NUMLOCK   = 0x90        # NUM LOCK key
  $R_Key_SCROLL    = 0x91        # SCROLL LOCK key
  #--------------------------------------------------------------------------
  $R_Key_LSHIFT    = 0xA0        # Left SHIFT key
  $R_Key_RSHIFT    = 0xA1        # Right SHIFT key
  $R_Key_LCONTROL  = 0xA2        # Left CONTROL key
  $R_Key_RCONTROL  = 0xA3        # Right CONTROL key
  $R_Key_L_ALT     = 0xA4        # Left ALT key
  $R_Key_R_ALT     = 0xA5        # Right ALT key
  #--------------------------------------------------------------------------
  $R_Key_SEP       = 0xBC        # , key
  $R_Key_DASH      = 0xBD        # - key
  $R_Key_DOTT      = 0xBE        # . Key
  #--------------------------------------------------------------------------
  GetKeyState = Win32API.new("user32","GetAsyncKeyState",['I'],'I')
  GetKeyboardState = Win32API.new("user32","GetKeyState",['I'],'I')
  GetSetKeyState = Win32API.new("user32","SetKeyboardState",['I'],'I')
  #--------------------------------------------------------------------------
  module_function
  #--------------------------------------------------------------------------
  def keyb(rkey)
     if GetKeyState.call(rkey) != 0
       return 1
     end
     return 0
  end
  #--------------------------------------------------------------------------
  def keyboard(rkey)
    GetKeyState.call(rkey) & 0x01 == 1
  end
  #--------------------------------------------------------------------------
  def key(rkey, key = 0)
    GetKeyboardState.call(rkey) & 0x01 == key
  end
  #--------------------------------------------------------------------------
end

Thanks in advance for helping me out another time :D
 
I tried that and it worked as in enabling the keys mentioned above, but it also made another error occur (logically): The Input processing of (Input::x) won't work anymore... for Input.trigger, that's not a problem at all because you can replace it easily with Kboard.keyboard of cybersam's script, but there's no function for Input.press... some way to only check the input from specific keys and disable Input.update for everything else?
 
Use this one instead:
Code:
#===============================================================================
# ** Keyboard Script v2 - This script was first created by Cybersam and she 
#                         deserves most of the credit, all I did was add a few 
#                         functions. (Astro_Mech says)
#-------------------------------------------------------------------------------
# Author    Cybersam
# Version   2.0
# Date      11-04-06
# Edit      Astro_mech
#===============================================================================
#-------------------------------------------------------------------------------
# Begin SDK Enabled Check
#-------------------------------------------------------------------------------
SDK.log("Input", "Cybersam", 2, "11.04.06")

module Input
  if SDK.state("Input") == true
  #--------------------------------------------------------------------------
  # * Variable Setup
  #-------------------------------------------------------------------------- 
    @keys = []
    @pressed = []
    Mouse_Left = 1
    Mouse_Right = 2
    Mouse_Middle = 4
    Back= 8
    Tab = 9
    Enter = 13
    Shift = 16
    Ctrl = 17
    Alt = 18
    Esc = 27
    Space = 32
    Numberkeys = {}
    Numberkeys[0] = 48        # => 0
    Numberkeys[1] = 49        # => 1
    Numberkeys[2] = 50        # => 2
    Numberkeys[3] = 51        # => 3
    Numberkeys[4] = 52        # => 4
    Numberkeys[5] = 53        # => 5
    Numberkeys[6] = 54        # => 6
    Numberkeys[7] = 55        # => 7
    Numberkeys[8] = 56        # => 8
    Numberkeys[9] = 57        # => 9
   # NumberUpKeys = {}
   # NumberUpKeys[0] = "!"
   # NumberUpKeys[1] = "@"
   # NumberUpKeys[2] = "#"
   # NumberUpKeys[3] = "$"
   # NumberUpKeys[4] = "%"
   # NumberUpKeys[5] = "^"
   # NumberUpKeys[6] = "&"
   # NumberUpKeys[7] = "*"
   # NumberUpKeys[8] = "("
   # NumberUpKeys[9] = ")"
    Numberpad = {}
    Numberpad[0] = 45
    Numberpad[1] = 35
    Numberpad[2] = 40
    Numberpad[3] = 34
    Numberpad[4] = 37
    Numberpad[5] = 12
    Numberpad[6] = 39
    Numberpad[7] = 36
    Numberpad[8] = 38
    Numberpad[9] = 33
    Letters = {}
    Letters["A"] = 65
    Letters["B"] = 66
    Letters["C"] = 67
    Letters["D"] = 68
    Letters["E"] = 69
    Letters["F"] = 70
    Letters["G"] = 71
    Letters["H"] = 72
    Letters["I"] = 73
    Letters["J"] = 74
    Letters["K"] = 75
    Letters["L"] = 76
    Letters["M"] = 77
    Letters["N"] = 78
    Letters["O"] = 79
    Letters["P"] = 80
    Letters["Q"] = 81
    Letters["R"] = 82
    Letters["S"] = 83
    Letters["T"] = 84
    Letters["U"] = 85
    Letters["V"] = 86
    Letters["W"] = 87
    Letters["X"] = 88
    Letters["Y"] = 89
    Letters["Z"] = 90
    Fkeys = {}
    Fkeys[1] = 112
    Fkeys[2] = 113
    Fkeys[3] = 114
    Fkeys[4] = 115
    Fkeys[5] = 116
    Fkeys[6] = 117
    Fkeys[7] = 118
    Fkeys[8] = 119
    Fkeys[9] = 120
    Fkeys[10] = 121
    Fkeys[11] = 122
    Fkeys[12] = 123
    Collon = 186        # => \ |
    Equal = 187         # => = +
    Comma = 188         # => , <
    Underscore = 189    # => - _
    Dot = 190           # => . >
    Backslash = 191     # => / ?
    Lb = 219
    Rb = 221
    Quote = 222         # => '"
#-------------------------------------------------------------------------------
    USED_KEYS = [Mouse_Left, Mouse_Right, Mouse_Middle] 
#-------------------------------------------------------------------------------
  module_function
  #--------------------------------------------------------------------------
  # * Check (key)
  #-------------------------------------------------------------------------- 
  def triggerd?(key)
    Win32API.new("user32","GetAsyncKeyState",['i'],'i').call(key) & 0x01 == 1  # key 0
  end
  #-------------------------------------------------------------------------- 
  def check(key)
    Win32API.new("user32","GetAsyncKeyState",['i'],'i').call(key) & 0x01 == 1  # key 0
  end
  #-----------------------------------------------------------------------
  # * Pressed ? (key)
  #-------------------------------------------------------------------------- 
  def pressed?(key)
    return true unless Win32API.new("user32","GetKeyState",['i'],'i').call(key).between?(0, 1)
    return false
  end
  #--------------------------------------------------------------------------
  # * Mouse Update
  #-------------------------------------------------------------------------- 
  def mouse_update
    @used_i = []
    for i in USED_KEYS
      x = check(i)
      if x == true
        @used_i.push(i)
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Short Write C
  #-------------------------------------------------------------------------- 
  def self.C
    self.trigger?(C)
  end
  #--------------------------------------------------------------------------
  # * Short Write B
  #-------------------------------------------------------------------------- 
  def self.B
    self.trigger?(B)
  end
  #--------------------------------------------------------------------------
  # * Short Write A
  #-------------------------------------------------------------------------- 
  def self.A
    self.trigger?(A)
  end
  #--------------------------------------------------------------------------
  # * Short Write Down
  #-------------------------------------------------------------------------- 
  def self.Down
    self.trigger?(DOWN)
  end
  #--------------------------------------------------------------------------
  # * Short Write Up
  #-------------------------------------------------------------------------- 
  def self.Up
    self.trigger?(UP)
  end
  #--------------------------------------------------------------------------
  # * Short Write Right
  #-------------------------------------------------------------------------- 
  def self.Right
    self.trigger?(RIGHT)
  end
  #--------------------------------------------------------------------------
  # * Short Write Left
  #-------------------------------------------------------------------------- 
  def self.Left
    self.trigger?(LEFT)
  end
  #--------------------------------------------------------------------------
  # * Anykey pressed?  ( A or B or C or Down or Up or Right or Left )
  #-------------------------------------------------------------------------- 
  def self.Anykey
    if A or B or C or Down or Up or Right or Left
      return true
    else
      return false
    end
  end
end
end

#-------------------------------------------------------------------------------
# End SDK Enabled Check
#-------------------------------------------------------------------------------

It's better! All keys works fine!
 
Okay, I tried this just now (took me some time to change everything...) and I'm finished with that part of the script now... I'm just curious of two things...

1st: Isn't this just like Near's script? ^_^
2nd: Is there a replacement for Input.repeat ?

On a side note, the keys stated above aren't working with this version either, but this version supports the Input.press function, so it fits my needs by removing Input.update ^_^

Thanks again.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top