如何解决Gma.UserActivityMonitorC#发出SendKeys问题
|| 我正在创建一个自动化工具,用于使用“ 0”将文本发送到发送窗口表单应用程序以外的其他所有窗口。我使用Gma.UserActivityMonitor库通过热键命令将工具设置为\“ type \”,可通过以下网址获得:http://www.codeproject.com/KB/cs/globalhook.aspx 我的问题是,当我使用热键来处理按键来触发键入时,有时它仍然允许按键滑过。 我试图启动一个新线程并在那里使用sendkeys,但是由于目标应用程序不接受输入,我得到一个错误,我应该使用SendKeys.SendWait
。
因此,我的问题可以通过以下两种方式之一回答:
1)我可以在哪个方向寻找有关多线程和使用sendkey的更多信息?
2)如何确保库中的钩子管理器正确禁止了触发按键?
我允许用户构建由不同字母作为关键字的字典,因此不同的字母会将不同的字符串发送到目标应用程序。
相关代码:
private void HookManager_KeyPress(object sender,KeyPressEventArgs e)
{
//code to generate tValue from the pressed key
if (tAutoTyperDictionary.ContainsKey(tValue))
{
//Should prevent the key from being passed to the window
//works sometimes
e.Handled = true;
AutoType();
}
}
private void AutoType()
{
int tCount = 0;
string tLine = tAutoTyperDictionary[tCurrentAutotypeKey];
//I remove the listener to prevent it calling itself
HookManager.KeyPress -= new KeyPressEventHandler(HookManager_KeyPress);
while (tCount < tLine.Length)
{
SendKeys.Send(tLine[tCount].ToString());
Thread.Sleep(10);
tCount++;
}
HookManager.KeyPress += new KeyPressEventHandler(HookManager_KeyPress);
}
解决方法
您是否尝试过SendKeys.SendWait(string keys)而不是Thread.Sleep(10)?
SendWait等待直到清除发送的密钥后再继续。
, 这是我编写的静态线程类,在这种情况下可能有用:
public static class threadClass
{
private static Thread _thread;
public static Thread thread
{
get { return _thread; }
}
public static void startThread()
{
_thread = new Thread(delegate() { });
_thread.Start();
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。