Artfunkel's picture

Scan code keyboard data

Project:The Open Toolkit library
Version:all versions
Category:feature request

This patch adds scan code support to OpenTK's keyboard system.

  • Keyboard events include the scan code
  • Scan codes can be checked on the keyboard object (use uint instead of Key)
  • Events are now generated even when an unknown key is pressed (you receive Key.Unknown and the scan code)

Example of use:

if (Keyboard[0x11]) // W
	KeyOffset.Y -= offset;
if (Keyboard[0x1E]) // A
	KeyOffset.X += offset;
if (Keyboard[0x1F]) // S
	KeyOffset.Y += offset;
if (Keyboard[0x20]) // D
	KeyOffset.X -= offset;

The above code allows WASD to be mapped correctly even if the user has a non-QWERTY keyboard layout.


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
AndyKorth's picture


Hey Artfunkel, do you think you could create a new patch that ignores whitespace changes? It looks like the entire HIDInput.cs file changed, but it was probably just the line ending characters or something like that.

I think svn diff -x --ignore-space-change or -x --ignore-all-space should do the trick.. If it doesn't work out, it's not a huge deal, but I had a bunch of changes to HIDInput.cs, so it would make for some manual conflict finding.


Artfunkel's picture


AndyKorth's picture


Thanks, will take a look tomorrow!

AndyKorth's picture


Sorry for the delay. I applied the patch locally and was testing it and found that it crashes the Mono vm on my mac.. Unfortunately without a stack trace, which is making it sort of a pain to track down.

The call that seems to do it in is:

I'll look into it a bit more. Just wanted to give you an update since it's been a few days.

AndyKorth's picture