模拟X秒一个按键 [英] Simulate a keypress for X seconds

查看:166
本文介绍了模拟X秒一个按键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的代码,我用它来模拟在一定的工艺制表按键:

Here is my code that I use to simulate a tab-keypress in a certain process:

[DllImport("user32.dll")]
static extern bool PostMessage(IntPtr hWnd, UInt32 Msg, int wParam, int lParam);

public Form1()
{
    PostMessage(MemoryHandler.GetMainWindowHandle(), 
               (int)KeyCodes.WMessages.WM_KEYDOWN, 
               (int)KeyCodes.VKeys.VK_TAB, 0);

    InitializeComponent();
}



有没有什么办法,使其塑机(例如钥匙将其扩展)1秒,而不是只攻呢?

Is there any way to extend it so that it presses the key for (example) 1 second, instead of just tapping it?

请注意,我不感兴趣,在 Thread.sleep代码()解决方案,阻止UI线程。

Please note that I'm not interested in a Thread.Sleep() solution that blocks the UI thread.

推荐答案

在一个按键,当你按住重复是的内置功能到键盘控制器。该内置于键盘本身的微处理器。该 8042微控制器是传统的选择,键盘设备驱动程序仍然带有它的名字。

The repeating of a keystroke when you hold it down is a feature that's built into the keyboard controller. A microprocessor that's built into the keyboard itself. The 8042 microcontroller was the traditional choice, the keyboard device driver still carries its name.

所以,不,这不是由Windows和PostMessage的()所做的是不会为你做它。不完全是一个问题,你可以简单地用一个定时器效仿。

So, no, this is not done by Windows and PostMessage() is not going to do it for you. Not exactly a problem, you can simply emulate it with a Timer.

这篇关于模拟X秒一个按键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆