Keycodes - American Keyboard

I would like to know the keycodes for the three keys (labeled A, B, C) in the image for a typical United States keyboard.

The following code snippet can be used to print the keycodes to the screen.

class ToolKeyPrinter
  @key_pressed = "-1"
  def onKeyDown(key, repeat, flags, view)
    @key_pressed = key.to_s

  def draw(view)
    style = {
      :font => "Arial",
      :size => 50,
      :bold => true,
      :align => TextAlignLeft,
      :color => "orange"
    view.draw_text([30, 30, 0], @key_pressed, style)


I don’t know enough about Ruby to really be helpful here. But I do have a basic background in font design and I’m little familiar with glyph mapping.

fwiw… the Unicode values for the 3 glyphs you mention are:

  • Tilde ~ : U+02DC
  • Less < : U+003C
  • Greater > : U+003E

But that might not mean anything if Ruby doesn’t recognize such descriptions, so maybe some other conversion/name is more useful… and if so maybe the following can help.

On MS Windows, US “qwerty” keyboard:
,(<) = 188
.(>) = 190
`(~) = 192

I do not get a response for clicking backtick. I only get 192 when SHIFT is pressed for a tilde.
EDIT: mea culpa, I had a shortcut assigned to backtick key.

BTW, keycodes can differ between Windows and Mac keyboards. This topic has been discussed over the years. If you cannot find it here, check the Ruby forum at SketchUcation for topics. (I seem to remember some code snippets were posted that defined VK_ prefixed constants for extensions.)

Thanks. Those are the numbers I’m after. It’s for a custom plugin, Windows only. Regarding the ~, is it possible that you have a shortcut on that key - if so Sketchup will just exit the snippet tool.

1 Like

Yes you are correct. I had "`" set to a Drill Down command that is not actually loaded at the moment. So nothing was happening when I pressed that key.

Testing in an older SketchUp version where I had not played with that key shows it returns 192.