0

I am implementing my own version of PSHostRawUserInterface. I'd like to implement PSHostRawUserInterface.ReadKey(), and therefore I need to map System.Management.Automation.Host.KeyInfo.VirtualKeyCode to System.ConsoleKeyInfo.Key.

I can cast System.ConsoleKeyInfo.Key to an int, I just don't know if that's actually the VirtualKeyCode.

Justin Dearing
  • 14,270
  • 22
  • 88
  • 161

1 Answers1

2

I think I tested this some time back and the answer was "yes, but." See below for cautions. You can test that answer by writing a program that outputs the integer values of all the ConsoleKey values and compares them to the Virtual Key Codes.

Note, though, that ConsoleKeyInfo.Key is just the key, without the modifiers. A Virtual Key Code is a bitmapped value that includes modifiers (Shift, Control, Alt). With ConsoleKeyInfo, the modifiers are stored in the Modifiers property.

Alternately, you could compare the values of the ConsoleKey enumeration to the values of the Keys enumeration, which specifically says that the values correspond to virtual key codes.

Jim Mischel
  • 131,090
  • 20
  • 188
  • 351
  • Jim, didn't test this yet, but I also found a utility to get keyboard scan codes: http://www.winterdrache.de/freeware/utilities.html – Justin Dearing Nov 28 '12 at 16:44