在的AutoIt V3 有一个调用的函数的 HotKeySet 的。它设置一个热键,调用时pressed用户的功能。这是一个全系统的热键,这意味着密钥不能被用于任何时热键设置其他
基本上,我想搭上 Esc键或其它键,像 $
,`
等,当用户presses在任何地方,甚至外面的应用程序,它应该让我知道。
例如,我会做这样HotKeySet({ESC})一个循环内,并且当它这样做,该方案将等待该密钥是前pssed $ P $。
公共静态无效的工作(){
而(真){
字符串任务= NULL;
锁(更衣室)
如果(tasks.Count大于0){
任务= tasks.Dequeue();
如果(任务== NULL){
返回;
}
}
如果(任务!= NULL){
//MessageBox.Show("Performing任务:+任务);
Program.mainAnnounceWindow.setLogTextBox(任务);
Program.mainAnnounceWindow.setLogTrayTip(任务);
Program.windowStateChange(显示);
//这里设置的热键
SetHotkey(`);
//等待热键preSS时,它的pssed $ P $ ...执行一些东西
Thread.sleep代码(5000); //模拟工作...
Program.windowStateChange(隐藏);
}
其他 {
wh.WaitOne(); //没有更多的任务 - 等待信号
}
}
}
解决方案
您需要看看的的 RegisterHotKey 的中的 user32.dll中。那里pinvoke.net, RegisterHotKey(USER32) 的。
In AutoIt v3 there's a function called HotKeySet. It sets a hotkey that calls a user function when pressed. It's a system wide hotkey, meaning that the key can't be used for anything else when the hotkey is set.
Basically, I would like to catch Esc or any other key like $
, `
, etc. and when the user presses it anywhere, even outside of the application, it should let me know.
For example, I would do like HotKeySet({ESC}) inside a loop and when it's done, the program would wait for that key to be pressed before.
public static void work() {
while (true) {
string task = null;
lock (locker)
if (tasks.Count > 0) {
task = tasks.Dequeue();
if (task == null) {
return;
}
}
if (task != null) {
//MessageBox.Show("Performing task: " + task);
Program.mainAnnounceWindow.setLogTextBox(task);
Program.mainAnnounceWindow.setLogTrayTip(task);
Program.windowStateChange("Show");
// Set the hotkey here
SetHotkey(`);
//Wait for hotkey to press when it's pressed... Execute some stuff
Thread.Sleep(5000); // Simulate work...
Program.windowStateChange("Hide");
}
else {
wh.WaitOne(); // No more tasks - wait for a signal
}
}
}
解决方案
You need to take a look at RegisterHotKey in user32.dll. There a good example at pinvoke.net, RegisterHotKey (user32).