Quote:
|
Originally Posted by crawforddavid2006
again, thankyou, that worked perfectly. also thank you for taking the time to explain what was going on.
|
Glad to see it's working. However, I have a suggestion for you. Assuming you're creating a class to simulate input (and if you are, you can combine the mouse and keyboard simulation in the same class), you might want to 'wrap' the call to
keybd_event() and have your public method use the
Keys enumeration directly:
public static class VirtualKeyboard
{
[DllImport("user32.dll")] static extern uint keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);
public static KeyDown(System.Windows.Forms.Keys key)
{
keybd_event((byte)key, 0, 0, 0);
}
public static KeyUp(System.Windows.Forms.Keys key)
{
keybd_event((byte)key, 0, 0x7F, 0);
}
}
Doing it like this has three advantages. First, you don't need to port in the virtual key constants; you can use the ones in the
System.Windows.Forms.Keys enumeration. Second, by using an enum, the calling code can only simulate keys for which there is a defined value (no passing in random numeric values). Third, it's clearer because there are two methods that take a single parameter, rather than one method with four (arguably more obscure) parameters. I mean, knowing the names and parameters of those two methods there makes it pretty clear what they do.