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.

[Purposefully resolved] ASCII Keyboard Values

Great, first time trying to do something with the full keyboard spec in VX, and it totally fucks my brain... so yeah, hope anyone can help...

I was basically working with alternate inputs, using directly ASCII numbers within the Input commands instead of methods like 'Input::C'... what I did was this:
Code:
if Input.trigger?(13) # Enter Key
  # code going here
end
That works flawlessly and without any imaginable problem. Well, I tried it with Ctrl then, being the ASCII value '17', but when I pressed it ingame, it didn't do anything. I checked a couple of other keys, and well... 'Q' is apparently associated with value 17...

So yeah, I can tell you I checked if it's caused by the German keyboard layout, but that's not the case. I have no idea why else that wouldn't work, since I'm pretty sure it did in XP... or I need an addition to the Input module and don't realize it... either way, please give me some input on this, thanks in advance.
 
I have a little program I made to see what ASCII number every key has, it too said that Ctrl is 17 and Q is 81, it may be something with the RMVX default keys.

Edit:
ya it is, try this "p Input::L" it prints out 17 so that's why it's Q instead of Ctrl :thumb:
 
K, so I need to Input methods eat the respective ASCII numbers instead of the included ones... well, as far as I figured it by now, that's what this snippet does:
Code:
# from Cybersam's Keyboard Input Module
def trigger?(key)
  Win32API.new("user32","GetAsyncKeyState",['i'],'i').call(key) & 0x01 == 1
end
Well, guess what, it still computes Q as 17 instead of Ctrl, which is fucked :p Anyone know how I can access the 'real' ACSII values? Or am I just missing a little bit of code here?
(It's a little confusing because they obviously kept the 13 (Return key), but didn't keep the 17 (Ctrl), which is a recognized-by-the-system-key as well...)

Man, this would be way easier if Input wouldn't be a fucking hidden module...
 
The Cybersam's Keyboard Script uses a module called Keyboard insteand of the Input one, I think. Or it was another one? Don't remember well.
So if I am right, you should use:
Code:
if Keyboard.trigger?(13) # Enter Key
  # code going here
end
Because Input will call the default method, which has another kind of values for the keys.

If I'm not right, I don't know. Try with another script.

Edit, if you want a complete list of the virtual keys codes, here is my Keys module:
Code:
#=============================================================================
# ** Module Keys
#=============================================================================
module Keys
  #---------------------------------------------------------------------------
  # * Mouse Buttons
  #---------------------------------------------------------------------------
  MOUSE_LEFT      = 1 # Mouse primary button (Normaly the left button)
  MOUSE_RIGHT     = 2 # Mouse secondary button (Normaly the right button)
  MOUSE_MIDDLE    = 4 # Mouse middle button
  MOUSE_4TH       = 5 # Mouse fourth button
  MOUSE_5TH       = 6 # Mouse fifth button
  #---------------------------------------------------------------------------
  # * Miscellaneous Keys
  #---------------------------------------------------------------------------
  CANCEL        = 3   # Cancel key
  BACKSPACE     = 8   # Backspace key
  TAB           = 9   # Tab key
  CLEAR         = 12  # Clear key
  RETURN        = 13  # Enter key
  SHIFT         = 16  # Shift key
  CTRL          = 17  # Control key
  ALT           = 18  # Alt key
  PAUSE         = 19  # Pause key
  ESCAPE        = 27  # Escape key
  SPACE         = 32  # Space bar key
  PGUP          = 33  # Page Up key
  PGDN          = 34  # Page Down key
  ENDS          = 35  # End key
  HOME          = 36  # Home key
  LEFT          = 37  # Left Arrow key
  UP            = 38  # Up Arrow key
  RIGHT         = 39  # Right Arrow key
  DOWN          = 40  # Down Arrow key
  SNAPSHOT      = 44  # Print Screen key
  SELECT        = 41  # Select key
  PRINT         = 42  # Print key
  EXECUTE       = 43  # Execute key
  INSERT        = 45  # Insert key
  DELETE        = 46  # Delete key
  HELP          = 47  # Help key
  LEFT_SHIFT    = 160 # Left Shift key
  RIGHT_SHIFT   = 161 # Right Shift key
  LEFT_CONTROL  = 162 # Left Control key
  RIGHT_CONTROL = 163 # Right Control key
  LEFT_ALT      = 164 # Left Alt key
  RIGHT_ALT     = 165 # Right Alt key
  #---------------------------------------------------------------------------
  # * Number Keys
  #---------------------------------------------------------------------------
  N0 = 48 # 0 key
  N1 = 49 # 1 key
  N2 = 50 # 2 key
  N3 = 51 # 3 key
  N4 = 52 # 4 key
  N5 = 53 # 5 key
  N6 = 54 # 6 key
  N7 = 55 # 7 key
  N8 = 56 # 8 key
  N9 = 57 # 9 key
  #---------------------------------------------------------------------------
  # * Letters Keys
  #---------------------------------------------------------------------------
  A = 65 # A key
  B = 66 # B key
  C = 67 # C key
  D = 68 # D key
  E = 69 # E key
  F = 70 # F key
  G = 71 # G key
  H = 72 # H key
  I = 73 # I key
  J = 74 # J key
  K = 75 # K key
  L = 76 # L key
  M = 77 # M key
  N = 78 # N key
  O = 79 # O key
  P = 80 # P key
  Q = 81 # Q key
  R = 82 # R key
  S = 83 # S key
  T = 84 # T key
  U = 85 # U key
  V = 86 # V key
  W = 87 # W key
  X = 88 # X key
  Y = 89 # Y key
  Z = 90 # Z key
  #---------------------------------------------------------------------------
  # * Windows Keys
  #---------------------------------------------------------------------------
  LWIN                = 91  # Left Windows key (Microsoft Natural keyboard) 
  RWIN                = 92  # Right Windows key (Natural keyboard)
  APPS                = 93  # Applications key (Natural keyboard)
  SLEEP               = 95  # Computer Sleep key
  BROWSER_BAK         = 166 # Browser Back key
  BROWSER_FORWARD     = 167 # Browser Forward key
  BROWSER_REFRESH     = 168 # Browser Refresh key
  BROWSER_STOP        = 169 # Browser Stop key
  BROWSER_SEARCH      = 170 # Browser Search key 
  BROWSER_FAVORITES   = 171 # Browser Favorites key
  BROWSER_HOME        = 172 # Browser Start and Home key
  VOLUME_MUTE         = 173 # Volume Mute key
  VOLUME_DOWN         = 174 # Volume Down key
  VOLUME_UP           = 175 # Volume Up key
  MEDIA_NEXT_TRACK    = 176 # Next Track key
  MEDIA_PREV_TRACK    = 177 # Previous Track key
  MEDIA_STOP          = 178 # Stop Media key
  MEDIA_PLAY_PAUSE    = 179 # Play/Pause Media key
  LAUNCH_MAIL         = 180 # Start Mail key
  LAUNCH_MEDIA_SELECT = 181 # Select Media key
  LAUNCH_APP1         = 182 # Start Application 1 key
  LAUNCH_APP2         = 183 # Start Application 2 key
  PROCESS             = 229 # Proccess key
  ATTN                = 246 # Attn key
  CRSEL               = 247 # CrSel key
  EXSEL               = 248 # ExSel key
  EREOF               = 249 # Erase EOF key
  PLAY                = 250 # Play key
  ZOOM                = 251 # Zoom key
  PA1                 = 253 # PA1 key
  #---------------------------------------------------------------------------
  # * Pad Keys
  #---------------------------------------------------------------------------
  NUMPAD0   = 96  # 0 key
  NUMPAD1   = 97  # 1 key
  NUMPAD2   = 98  # 2 key
  NUMPAD3   = 99  # 3 key
  NUMPAD4   = 100 # 4 key
  NUMPAD5   = 101 # 5 key
  NUMPAD6   = 102 # 6 key
  NUMPAD7   = 103 # 7 key
  NUMPAD8   = 104 # 8 key
  NUMPAD9   = 105 # 9 key
  MULTIPLY  = 106 # Multiply key (*)
  ADD       = 107 # Add key (+)
  SEPARATOR = 108 # Separator key
  SUBTRACT  = 109 # Subtract key (-)
  DECIMAL   = 110 # Decimal key (.)
  DIVIDE    = 111 # Divide key (/)
  #---------------------------------------------------------------------------
  # * F Keys
  #---------------------------------------------------------------------------
  F1  = 112  # F1 key
  F2  = 113  # F2 key
  F3  = 114  # F3 key
  F4  = 115  # F4 key
  F5  = 116  # F5 key
  F6  = 117  # F6 key
  F7  = 118  # F7 key
  F8  = 119  # F8 key
  F9  = 120  # F9 key
  F10 = 121  # F10 key
  F11 = 122  # F11 key
  F12 = 123  # F12 key
  F13 = 124  # F13 key
  F14 = 125  # F14 key
  F15 = 126  # F15 key
  F16 = 127  # F16 key
  F17 = 128  # F17 key
  F18 = 129  # F18 key
  F19 = 130  # F19 key
  F20 = 131  # F20 key
  F21 = 132  # F21 key
  F22 = 133  # F22 key
  F23 = 134  # F23 key
  F24 = 135  # F24 key
  #---------------------------------------------------------------------------
  # * Mode Keys
  #---------------------------------------------------------------------------
  CAPS_LOCK   = 20  # Caps lock key
  NUM_LOCK    = 144 # Num lock key
  SCROLL_LOCK = 145 # Scroll lock key
  KANA        = 21  # Kana key
  JUNJA       = 23  # Junja key
  FINAL       = 24  # Final key
  KANJI       = 25  # Kanji key
  CONVERT     = 28  # Convert key
  NONCONVERT  = 29  # Non convert key
  ACCEPT      = 30  # Accept key
  MODECHANGE  = 31  # Mode change request key
  #---------------------------------------------------------------------------
  # * OEM Keys
  #   - Keys used for miscellaneous characters; they can vary by keyboard.
  #---------------------------------------------------------------------------
  OEM_1     = 186 # In USA 101/102 keyboards (; :)
  OEM_2     = 187 # In USA 101/102 keyboards (= +)
  OEM_3     = 188 # In USA 101/102 keyboards (, <)
  OEM_4     = 189 # In USA 101/102 keyboards (- _)
  OEM_5     = 190 # In USA 101/102 keyboards (. >)
  OEM_6     = 191 # In USA 101/102 keyboards (/ ?)
  OEM_7     = 192 # In USA 101/102 keyboards (` ~)
  OEM_8     = 219 # In USA 101/102 keyboards ([ {)
  OEM_9     = 220 # In USA 101/102 keyboards (\ |)
  OEM_10    = 221 # In USA 101/102 keyboards (] })
  OEM_11    = 222 # In USA 101/102 keyboards (' ")
  OEM_13    = 223 # OEM key
  OEM_14    = 226 # OEM key
  OEM_15    = 146 # OEM key
  OEM_16    = 147 # OEM key
  OEM_17    = 148 # OEM key
  OEM_18    = 149 # OEM key
  OEM_19    = 150 # OEM key
  OEM_20    = 225 # OEM key
  OEM_21    = 227 # OEM key
  OEM_22    = 228 # OEM key
  OEM_23    = 230 # OEM key
  OEM_24    = 232 # OEM key
  OEM_25    = 240 # OEM key
  OEM_26    = 241 # OEM key
  OEM_27    = 242 # OEM key
  OEM_28    = 243 # OEM key
  OEM_29    = 244 # OEM key
  OEM_30    = 245 # OEM key
  OEM_CLEAR = 254 # OEM Clear key
  #---------------------------------------------------------------------------
  # * Keys Names
  #---------------------------------------------------------------------------
  KEYS_NAMES = {1=>'Mouse Primary',2=>'Mouse Secondary',3=>'Cancel',
  4=>'Mouse Middle',5=>'Mouse 4th',6=>'Mouse 5th',8=>'Backspace',9=>'Tab',
  12=>'Clear',13=>'Enter',16=>'Shift',17=>'Control',18=>'Alt',19=>'Pause',
  20=>'Capitals Lock',21=>'Kana',23=>'Junja',24=>'Final',25=>'Kanji',
  27=>'Escape',28=>'Convert',29=>'Non Convert',30=>'Accept',31=>'Mode Change',
  32=>'Space',33=>'Page Up',34=>'Page Down',35=>'End',36=>'Home',37=>'Left',
  38=>'Up',39=>'Right',40=>'Down',41=>'Select',42=>'Print',43=>'Execute',
  44=>'Snapshot',45=>'Insert',46=>'Delete',47=>'Help',48=>'0',49=>'1',50=>'2',
  51=>'3',52=>'4',53=>'5',54=>'6',55=>'7',56=>'8',57=>'9',65=>'A',66=>'B',
  67=>'C',68=>'D',69=>'E',70=>'F',71=>'G',72=>'H',73=>'I',74=>'J',75=>'K',
  76=>'L',77=>'M',78=>'N',79=>'O',80=>'P',81=>'Q',82=>'R',83=>'S',84=>'T',
  85=>'U',86=>'V',87=>'W',88=>'X',89=>'Y',90=>'Z',91=>'Left Windows',
  92=>'Right Windows',93=>'Application',95=>'Sleep',96=>'PAD 0',97=>'PAD 1',
  98=>'PAD 2',99=>'PAD 3',100=>'PAD 4',101=>'PAD 5',102=>'PAD 6',103=>'PAD 7',
  104=>'PAD 8',105=>'PAD 9',106=>'*',107=>'+',108=>'Separator',109=>'-',110=>'.',
  111=>'/',112=>'F1',113=>'F2',114=>'F3',115=>'F4',116=>'F5',117=>'F6',118=>'F7',
  119=>'F8',120=>'F9',121=>'F10',122=>'F11',123=>'F12',124=>'F13',125=>'F14',
  126=>'F15',127=>'F16',128=>'F17',129=>'F18',130=>'F19',131=>'F20',132=>'F21',
  133=>'F22',134=>'F23',135=>'F24',144=>'Number Lock',145=>'Scroll Lock',
  146=>'OEM 15',147=>'OEM 16',148=>'OEM 17',149=>'OEM 18',150=>'OEM 19',
  160=>'Left Shift',161=>'Right Shift',162=>' Left Control',163=>'Right Control',
  164=>' Left Alt',165=>'Right Alt',166=>'Browser Back',167=>'Browser Forward',
  168=>'Browser Refresh',169=>'Browser Stop',170=>'Browser Search',
  171=>'Browser Favorites',172=>'Browser Home',173=>'Volume Mute',
  174=>'Volume Down',175=>'Volume Up',176=>'Media Next Track',
  177=>'Media Previous Track',178=>'Media Stop',179=>'Media Play Pause',
  180=>'Launch Mail',181=>'Launch Media Select',182=>'Launch Application',
  183=>'Launch Application',186=>'OEM 1',187=>'OEM 2',188=>'OEM 3',189=>'OEM 4',
  190=>'OEM 5',191=>'OEM 6',192=>'OEM 7',219=>'OEM 8',220=>'OEM 9',221=>'OEM 10',
  222=>'OEM 11',223=>'OEM 13',225=>'OEM 20',226=>'OEM 14',227=>'OEM 21',
  228=>'OEM 22',229=>'Proccess',230=>'OEM 23',232=>'OEM 24',240=>'OEM 25',
  241=>'OEM 26',242=>'OEM 27',243=>'OEM 28',244=>'OEM 29',245=>'OEM 30',
  246=>'ATTN',247=>'CRSEL',248=>'EXSEL',249=>'EREOF',250=>'Play',251=>'Zoom',
  253=>'PA1',254=>'OEM Clear'}
  #---------------------------------------------------------------------------
  # * Virtual Key to Key Name
  #---------------------------------------------------------------------------
  def Keys.name?(vk)
    KEYS_NAMES[vk].nil? ? '???' : KEYS_NAMES[vk]
  end
  #---------------------------------------------------------------------------
  # * Virtual Key to Virtual Key Variable Name
  #---------------------------------------------------------------------------
  def Keys.var_name?(vk)
    Keys.constants.size.times do |index|
      if eval("Keys::#{Keys.constants[index]}") == vk
        return Keys.constants[index]
      end
    end
    '???'
  end
  #---------------------------------------------------------------------------
  # * Key Name to Virtual Key
  #---------------------------------------------------------------------------
  def Keys.vk?(name)
    KEYS_NAMES.invert[name].nil? ? 0 : KEYS_NAMES.invert[name]
  end
  #---------------------------------------------------------------------------
  # * Virtual Key Variable Name to Virtual Key
  #---------------------------------------------------------------------------
  def Keys.var_vk?(name)
    if Keys.constants.include?(name)
      eval("Keys::#{Keys.constants[Keys.constants.index(name)]}")
    else
      0
    end
  end
end
 
I wish the error would be that easy... but no, the version of his script I use (v4, I think... the one that was included in netplay+) modifies the Input module... well, here ya have it...
Code:
#==============================================================================
# Keyboard Input Module
#----------------------------------------------------------------------------
# Script by Cybersam
#==============================================================================

module Input
  @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
  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
  #--------------------------------------------------------------------------
  def triggered?(key)
    Win32API.new("user32","GetAsyncKeyState",['i'],'i').call(key) & 0x01 == 1
  end
  #-------------------------------------------------------------------------- 
  def check(key)
    Win32API.new("user32","GetAsyncKeyState",['i'],'i').call(key) & 0x01 == 1
  end
  #--------------------------------------------------------------------------
  def pressed?(key)
    return true unless Win32API.new("user32","GetKeyState",['i'],'i').call(key).between?(0, 1)
    return false
  end
  #--------------------------------------------------------------------------
  def mouse_update
    @used_i = []
    for i in USED_KEYS
      x = check(i)
      if x == true
        @used_i.push(i)
      end
    end
  end
  #--------------------------------------------------------------------------
  def self.C
    self.trigger?(C)
  end
  #-------------------------------------------------------------------------- 
  def self.B
    self.trigger?(B)
  end
  #-------------------------------------------------------------------------- 
  def self.A
    self.trigger?(A)
  end
  #-------------------------------------------------------------------------- 
  def self.Down
    self.trigger?(DOWN)
  end
  #-------------------------------------------------------------------------- 
  def self.Up
    self.trigger?(UP)
  end
  #-------------------------------------------------------------------------- 
  def self.Right
    self.trigger?(RIGHT)
  end
  #-------------------------------------------------------------------------- 
  def self.Left
    self.trigger?(LEFT)
  end
  #--------------------------------------------------------------------------
  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

But either way, I tried to get it to work without the script until now... because I couldn't spot anything within his script that translates the RM values to ASCII values, I figured that you should be able to use Input.trigger?(17) for CTRL anytime without any additional script... so yeah, since that obviously doesn't work, what would I have to do to recognize those values in ASCII instead?
 
The default Input module doesn't guide by the normal Virtual Key/VK Codes(ASCII codes), it uses anothers:
Input::DOWN = 2
Input::LEFT = 4
Input::RIGHT = 6
Input::UP = 8
Input::A = 11
Input::B = 12
Input::C = 13
Input::X = 14
Input::Y = 15
Input::Z = 16
Input::L = 17
Input::R = 18
Input::SHIFT = 19
Input::CTRL = 20
Input::ALT = 21
Input::F5 = 22
Input::F6 = 23
Input::F7 = 24
Input::F8 = 25
Input::F9 = 26
If I remember well they are correct, however none of these numbers correspond to the real VK codes. And also the A, B, C, X, Y, Z, L and R doesn't represent the real letters in the keyboard, they represents a kind of button cofiguration, which is editable by the F1 menu. So via the F1 menu you can assign the correspondent keys to this "buttons". Have you used an emulator? It works similar.
So the default input module doesn't have access to all keyboard keys.
With the Input module you have, you have to use: triggered? or pressed? insteand of press? and trigger?.
Code:
if Input.triggered?(13) # Enter Key
  # code going here
end
This has to work well.
 
I know all of the above, it's just that his keyboard input module won't work the way it should in VX, so yeah... let's rephrase this:

I could use anything that intercepts inbetween Input.trigger?(17) and whatever makes 17 not the accosiated number of CTRL. In other words, I'd need a script checking if the ASCII key is pressed, rather than RMVX' strange number system... or at least a hint at how the input modules do it, since they do it somehow...
 
Well, I tried to use a different KIM now, and well... that works as I need it to...
Doesn't solve the question what exactly makes RMVX recognize keyboard inputs, but well... I can work on as for now, so thanks to all contributors.

@Shingu: Umm... you're welcome.
 

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