[英]I want to be able to hold down control by code
我正在将c#,Visual Studio 2010用于Windows应用程序。
我想按住Ctrl键,然后过一会儿再释放它。
我试过了,但是没用。
[DllImport("user32.dll")]
static extern bool keybd_event(byte bVk, byte bScan, uint dwFlags,
UIntPtr dwExtraInfo);
public const uint KEYEVENTF_KEYUP = 0x02;
public const uint VK_CONTROL = 0x11;
// Press the Control key.
keybd_event(VK_CONTROL,0,0,0);
//release the control key
keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
但是我得到这个错误
最佳重载方法匹配为'ImageR.Form1.keybd_event(byte,byte,uint,System.UIntPtr)
无法从'uint'转换为'byte'
无法从“ int”转换为“ System.UIntPtr”
我找不到do SendInput
任何好例子, http: do SendInput
的例子对我不起作用。
解决此问题的最佳方法是在http://inputsimulator.codeplex.com/
现在很简单:
//Press Ctrl
InputSimulator.SimulateKeyDown(VirtualKeyCode.CONTROL);
//Release Ctrl
InputSimulator.SimulateKeyUp(VirtualKeyCode.CONTROL);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.