简体   繁体   English

我希望能够通过代码保持控制

[英]I want to be able to hold down control by code

I'm using c#, Visual Studio 2010 for a Windows application. 我正在将c#,Visual Studio 2010用于Windows应用程序。

I want to hold down the Ctrl key, then release it after a while. 我想按住Ctrl键,然后过一会儿再释放它。

I tried this but it didnt work. 我试过了,但是没用。

[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);

But I get this error 但是我得到这个错误

The best overloaded method match for 'ImageR.Form1.keybd_event(byte, byte, uint, System.UIntPtr) 最佳重载方法匹配为'ImageR.Form1.keybd_event(byte,byte,uint,System.UIntPtr)

cannot convert from 'uint' to 'byte' 无法从'uint'转换为'byte'

cannot convert from 'int' to 'System.UIntPtr' 无法从“ int”转换为“ System.UIntPtr”

I didn't find any good examples of do SendInput , the examples at http://www.pinvoke.net/default.aspx/user32.keybd_event didn't work for me. 我找不到do SendInput任何好例子, http: do SendInput的例子对我不起作用。

The best solution to solve this was at http://inputsimulator.codeplex.com/ 解决此问题的最佳方法是在http://inputsimulator.codeplex.com/

Now it's this simple: 现在很简单:

//Press Ctrl

InputSimulator.SimulateKeyDown(VirtualKeyCode.CONTROL);

//Release Ctrl

InputSimulator.SimulateKeyUp(VirtualKeyCode.CONTROL);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何通过代码按住Ctrl键 - How to hold the Ctrl key down through code 我想在后面的代码中的UL标签内添加图表控件 - I want to add a chart control inside a UL tag in code behind 我想知道在使用 webbrowser 时如何控制代码流? - I want to know how to control the flow of code when using webbrowser? 我想建立一个能够控制客户端计算机上的硬件的网站 - i want to make a web site which is able to control a hardware on a clients computer 我希望我的代码能够显示 3 个选项,如果登录是由 adm1 进行的,并且如果登录是由任何其他用户进行的,我希望可以看到提款/存款 - i want my code to be able to display 3 options if the log in is by adm1 and if the log in is by any other user i want the withdraw/deposit to be seen 我想停靠用户控制 - i want to dock User Control 找不到背后的代码的Web控件? - Not able to find the web control on code behind? 此代码是否像我希望的那样同步? - Is this code synchronous as I want it to be? 我希望能够在网页的代码隐藏中绘制线条 - I want to be able to draw lines in codebehind for webpage 我希望用户能够下载页面 - I want the user to be able to download a page
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM