How to push a key and release it using C#?(如何使用 C# 按下一个键并释放它?)
问题描述
我正在编写一个 C# 程序,它从外部设备捕获信号,并将击键发送到另一个应用程序.我正在使用 SendKeys,它工作正常.
I am writing a C# program which captures signals from a external device, and sends keystrokes to another application. I am using SendKeys and it works fine.
SendKeys 通过立即按住和释放某个键来按下"它.我想让它按键随意释放.
SendKeys does "press" a key by holding and releasing it immediately. I would like to make it push key and release it at will.
我的问题是:有没有办法向按键发送推"信号,然后在一定时间后发出释放"信号?"
My question is : "is there a way to send a "push" signal to a key, then a "release" signal after a certain amount of time ?"
我不确定 SendKeys 是否能够做到这一点.有什么线索吗?
I am not sure SendKeys is able to do this. Any clue ?
推荐答案
我不认为直接来自 .NET您可以尝试通过 p/invoking 此处描述的函数来使用 keybd_event 本地调用:http://pinvoke.net/default.aspx/user32.keybd_event
I don't think it's possible from .NET directly You could try using keybd_event native call by p/invoking the function as described here: http://pinvoke.net/default.aspx/user32.keybd_event
keybd_event 的 MSDN 在这里:http:///msdn.microsoft.com/en-us/library/ms646304(VS.85).aspx
The MSDN for keybd_event is here: http://msdn.microsoft.com/en-us/library/ms646304(VS.85).aspx
希望有帮助!
这篇关于如何使用 C# 按下一个键并释放它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 C# 按下一个键并释放它?


- 使用 rss + c# 2022-01-01
- 在 LINQ to SQL 中使用 contains() 2022-01-01
- Azure Active Directory 与 MVC,客户端和资源标识同一 2022-01-01
- C# 通过连接字符串检索正确的 DbConnection 对象 2022-01-01
- CanBeNull和ReSharper-将其用于异步任务? 2022-01-01
- 带问号的 nvarchar 列结果 2022-01-01
- 为什么 C# 中的堆栈大小正好是 1 MB? 2022-01-01
- Windows 喜欢在 LINUX 中使用 MONO 进行服务开发? 2022-01-01
- 在 C# 中异步处理项目队列 2022-01-01
- 是否可以在 .Net 3.5 中进行通用控件? 2022-01-01