如何使用 C# 按下一个键并释放它?

25

本文介绍了如何使用 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# 按下一个键并释放它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

C# 中的多播委托奇怪行为?
Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)...
2023-11-11 C#/.NET开发问题
6

参数计数与调用不匹配?
Parameter count mismatch with Invoke?(参数计数与调用不匹配?)...
2023-11-11 C#/.NET开发问题
26

如何将代表存储在列表中
How to store delegates in a List(如何将代表存储在列表中)...
2023-11-11 C#/.NET开发问题
6

代表如何工作(在后台)?
How delegates work (in the background)?(代表如何工作(在后台)?)...
2023-11-11 C#/.NET开发问题
5

没有 EndInvoke 的 C# 异步调用?
C# Asynchronous call without EndInvoke?(没有 EndInvoke 的 C# 异步调用?)...
2023-11-11 C#/.NET开发问题
2

Delegate.CreateDelegate() 和泛型:错误绑定到目标方法
Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)...
2023-11-11 C#/.NET开发问题
14