Edit SendInput's wParam and lParam
I need to simulate keyboard press on C#, so im using SendInput function
from InputSimulator DLL (http://inputsimulator.codeplex.com/). Checking
keypressing through spy++, I saw that there is difference between real
keyboard press and sendinput.
Real keyboard press:
WM_KEYDOWN nVirtKey:VK_DOWN cRepeat:1 ScanCode:50 fExtended:1 fAltDown:0
fRepeat:0 fUp:0 wParam: 00000028 lParam: 01500001 WM_KEYUP
nVirtKey:VK_DOWN cRepeat:1 ScanCode:50 fExtended:1 fAltDown:0 fRepeat:0
fUp:1 wParam: 00000028 lParam: C1500001
SendInput:
WM_KEYDOWN nVirtKey:VK_DOWN cRepeat:1 ScanCode:50 fExtended:0 fAltDown:0
fRepeat:0 fUp:0 wParam: 00000028 lParam: 00500001 WM_KEYUP
nVirtKey:VK_DOWN cRepeat:1 ScanCode:50 fExtended:0 fAltDown:0 fRepeat:0
fUp:1 wParam: 00000028 lParam: C0500001
As you can see, there are different wParam and lParam.
This is KeyDown function, i can edit some parameters, but i dont know,
what parameter will changes wParam and lParam:
public static void SimulateKeyDown(VirtualKeyCode keyCode, ushort
Scan, uint Flags, uint Time, IntPtr ExtraInfo)
{
INPUT down = new INPUT();
down.Type = 1;
down.Data.Keyboard = new KEYBDINPUT();
down.Data.Keyboard.Vk = (ushort) keyCode;
down.Data.Keyboard.Scan = Scan;//0
down.Data.Keyboard.Flags = Flags;//0
down.Data.Keyboard.Time = Time;//0
down.Data.Keyboard.ExtraInfo = ExtraInfo;//IntPtr.Zero
INPUT[] inputList = new INPUT[] { down };
if (SendInput(1, inputList, Marshal.SizeOf(typeof(INPUT))) == 0)
{
throw new Exception(string.Format("The key down simulation for
{0} was not successful.", keyCode));
}
}
No comments:
Post a Comment