我有一个带有5个按钮的C#表单.用户输入信息,并且根据按下功能键,执行特定动作.F9-Execute Order F6,F3-Save ,-LookUp.
我添加了愚蠢的代码:
OnForm_Load
this.KeyUp += new System.Windows.Forms.KeyEventHandler(KeyEvent);
Run Code Online (Sandbox Code Playgroud)
和
private void KeyEvent(object sender, KeyEventArgs e) //Keyup Event
{
if (e.KeyCode == Keys.F9)
{
MessageBox.Show("Function F9");
}
if (e.KeyCode == Keys.F6)
{
MessageBox.Show("Function F6");
}
else
MessageBox.Show("No Function");
}
Run Code Online (Sandbox Code Playgroud)
但没有任何反应
谢谢
我有一个应用程序,该应用程序始终检查是否F12按下了某个键。它不需要将焦点放在应用程序的主窗口上。我尝试了这段代码:
public int a = 1;
// DLL libraries used to manage hotkeys
[DllImport("user32.dll")]
public static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vlc);
[DllImport("user32.dll")]
public static extern bool UnregisterHotKey(IntPtr hWnd, int id);
const int MYACTION_HOTKEY_ID = 1;
public Form1()
{
InitializeComponent();
// Modifier keys codes: Alt = 1, Ctrl = 2, Shift = 4, Win = 8
// Compute the addition of each combination of the keys you want to be pressed
// ALT+CTRL = …Run Code Online (Sandbox Code Playgroud) 所以我有一个带有Form的C#控制台应用程序,我想用热键打开它.比如说Ctrl+ <打开表单.所以我现在得到了处理globalkeylistener的代码,但看起来我实现它失败了.它创建了一个while循环来阻止它关闭程序,我尝试使用kbh_OnKeyPressed方法从用户那里获得输入.
我试着用这种方式实现它:
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace Globalkey
{
static class Program
{
[DllImport("user32.dll")]
private static extern bool RegisterHotkey(int id, uint fsModifiers, uint vk);
private static bool lctrlKeyPressed;
private static bool f1KeyPressed;
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
LowLevelKeyboardHook kbh = new LowLevelKeyboardHook();
kbh.OnKeyPressed += kbh_OnKeyPressed;
kbh.OnKeyUnpressed += kbh_OnKeyUnpressed;
kbh.HookKeyboard();
while(true) { }
}
private static void kbh_OnKeyUnpressed(object sender, Keys e)
{
if (e == Keys.LControlKey)
{ …Run Code Online (Sandbox Code Playgroud) 我想编写简单的代码program,在某些地方发送我的用户和密码,例如当我想登录网站时,我发现了这个项目正在听键盘。
所以我有这个功能:
private void HookManager_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
{
}
private void HookManager_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
}
private void HookManager_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
}
Run Code Online (Sandbox Code Playgroud)
例如,当我按下 键时,a我会得到这样的结果:
int value = e.KeyValue; // 65
Keys key = e.KeyCode; // A
Run Code Online (Sandbox Code Playgroud)
所以我想知道如何捕获特定的keyboard combination而不是仅一个key的例子Ctrl + l?