日期:2014-05-17 浏览次数:20957 次
public void OnKeyPress(KeyboardHook.HookStruct hookStruct, out bool handle)
{
handle = false; //预设不拦截任何键
String keys = this.keys.Text.ToUpper();
Keys key = (Keys)hookStruct.vkCode;
//设定的键
if (keys.IndexOf(key.ToString()) != -1)
{
handle = true;
Test t = new Test();
Thread thre = new Thread(t.Continuous);
thre.IsBackground = true;
thre.Start('x');
}
}
public class Test
{
[DllImport("user32.dll", EntryPoint = "keybd_event")]
public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtralnfo);
public void Continuous(object key)
{
//int key1 = (int)key;
byte key2 = (byte)Convert.ToByte(key);
for (var i = 0; i < 5; i++)
{
keybd_event(key2, 0, 0, 0);
//Thread.Sleep(0);
}
}
}