InputBuilder Key Scan Codes

Oct 12, 2010 at 1:49 PM

Windows Input Simulator is an awesome solution to my virtual keyboard for WPF applications!

But I have noticed that Alt Codes do not work with it.

So I have used my previous solution and now I am posting it here.

Hopefully, the author will add this to the sources.

 

First, within the NativeMethods.cs I declare the following:

[System.Runtime.InteropServices.DllImport("user32.dll")]
internal static extern uint MapVirtualKey(uint uCode, uint uMapType);

internal enum MAPVK
{
MAPVK_VK_TO_VSC = 0x0,
MAPVK_VSC_TO_VK = 0x1,
MAPVK_VK_TO_CHAR = 0x2,
MAPVK_VSC_TO_VK_EX = 0x3,
}

Then, within the InputBuilder.cs I add the following lines to the AddKeyDown method:

uint VirtualScanCode = Native.NativeMethods.MapVirtualKey((uint)(keyCode), (uint)(Native.NativeMethods.MAPVK.MAPVK_VK_TO_VSC));
down.Data.Keyboard.Scan = (ushort)(VirtualScanCode);

Then, within the InputBuilder.cs I add the following lines to the AddKeyUp method:

uint VirtualScanCode = Native.NativeMethods.MapVirtualKey((uint)(keyCode), (uint)(Native.NativeMethods.MAPVK.MAPVK_VK_TO_VSC));
up.Data.Keyboard.Scan = (ushort)(VirtualScanCode);

And then Alt Codes begin to report correctly.