Artfunkel's picture

Scan code keyboard data

Project:The Open Toolkit library
Version:all versions
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:open
Description

http://pastebin.com/iKCC4dfg

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.


Comments

Comment viewing options

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

#1

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.

Thanks!
-Andy

Artfunkel's picture

#2

AndyKorth's picture

#3

Thanks, will take a look tomorrow!

AndyKorth's picture

#4

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:
OpenTK.Input.Keyboard.GetState()[Key.A]

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

#5