Global Hooks(非活动程序) [英] Global Hooks (non-active program)
问题描述
我正在创建一个程序,该程序允许您粘贴文本,但是看起来就像您在粘贴时键入文本一样,Paste Typer.
我想使用 Ctrl + b
取消粘贴,但是我在使用热键时遇到问题.
我认为我需要使用一个 WH_KEYBOARD_LL
钩子并包含该user32文件,但添加该文件和命名空间时通常会出错.
我与此最接近: http://thedarkjoker94.cer33.com/?p=111-但即使我使用了 KeyData
,它似乎也无法与 Ctrl
, alt
和其他修饰符一起使用.>
我需要一种使热键即使在该程序不是活动窗口时也可以使用的方法.这是Microsoft Visual C#2010中的Windows窗体应用程序.
有很多StackOverlow主题,但它们过时,而且不够完整,无法让我正常运行.
您是否在谈论 HookManager ?
我这样成功地使用它:
HookManager.KeyDown + =新的KeyEventHandler(HookManager_KeyDown);
和
void HookManager_KeyDown(对象发送者,KeyEventArgs e){if(Keyboard.IsKeyDown(Keys.LWin))//是否按下了Windows左键并...开关(e.KeyCode){案例Keys.O://...e.Handled = true;休息;案例Keys.H://...e.Handled = true;休息;}}
我创建了Keyboard类,这里是代码:
//二手:http://www.pinvoke.net/default.aspx/user32.getasynckeystate使用System.Runtime.InteropServices;使用System.Windows.Forms;命名空间Win32.Devices{公共课键盘{[DllImport("user32.dll")]静态外部超短GetAsyncKeyState(Keys vKey);公共静态布尔IsKeyDown(Keys key){返回0!=(GetAsyncKeyState(key)& 0x8000);}}}
I am creating a program that allows you to paste text but it will look like you are typing it as it pastes, Paste Typer.
I am wanting to use Ctrl + b
to set off the pasting, but I am having issues with hotkeys.
I think what I need is to use a WH_KEYBOARD_LL
hook and include that user32 file but I usually get errors when I add it and the namespace.
I have come closest with this: http://thedarkjoker94.cer33.com/?p=111 - but it doesn't seem to work with Ctrl
, alt
and other modifiers, even when I used KeyData
.
I need a way to make a hotkey that will work even when the program is not the active window. This is a windows forms application in Microsoft Visual C# 2010.
There a rea lot of StackOverlow topics but they are dated and are not complete enough for me to get something running.
Are you talking about the HookManager?
I use it successfully like this:
HookManager.KeyDown += new KeyEventHandler(HookManager_KeyDown);
and
void HookManager_KeyDown(object sender, KeyEventArgs e)
{
if (Keyboard.IsKeyDown(Keys.LWin)) // Is the Left-Windows Key down and ...
switch (e.KeyCode)
{
case Keys.O:
// ...
e.Handled = true;
break;
case Keys.H:
// ...
e.Handled = true;
break;
}
}
I created the Keyboard class here is the code:
// Used: http://www.pinvoke.net/default.aspx/user32.getasynckeystate
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace Win32.Devices
{
public class Keyboard
{
[DllImport("user32.dll")]
static extern ushort GetAsyncKeyState(Keys vKey);
public static bool IsKeyDown(Keys key)
{
return 0 != (GetAsyncKeyState(key) & 0x8000);
}
}
}
这篇关于Global Hooks(非活动程序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!