在尝试使用允许您选择所需热键的 Visual Studio Windows 窗体创建自动点击器应用程序时,我偶然发现了一个问题
当用户输入诸如~或/热键之类的键时,将不起作用,但是,如果我输入 0xC0 (用于波浪号)或 0xDC (用于斜线)而不是 (int)[波浪号] 或 (int)'/' 它将起作用.
最重要的是字母必须大写,但这没关系,因为我可以使用 ToUpper() 来大写它
允许用户选择字符的部分很好,它将字母作为字符串返回
这是我实现 RegisterHotKey() 和 UnregisterHotKey() 以及设置表单事件的地方:
[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);
protected override void WndProc(ref Message m) {
if (m.Msg == 0x0312 && m.WParam.ToInt32() == 1)
{
toggleClicker(); //This turns my autoclicker off and on
}
base.WndProc(ref m);
}
public Form1(){
InitializeComponent();
/* Ignore this:
VersionText.Text = "Version " + version;
comboBox1.SelectedIndex = 0;
*/
RegisterHotKey(this.Handle, 1, 0x0002, (int)Keys.P); //This is the default and it works just fine
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
UnregisterHotKey(this.Handle, 1);
}
这是用户选择他们想要的键时的代码
private void button2_Click(object sender, EventArgs e)
{
/*Ignore this
if (isClickerRunning)
{
//Console.WriteLine("Stopping...");
clickerThread.Abort();
isClickerRunning = false;
}
*/
int Prefix = 0;
//Set Prefix to the value chosen in the combobox
if (comboBox1.SelectedIndex == 1) { Prefix = 0x0002; } //Ctrl
if (comboBox1.SelectedIndex == 2) { Prefix = 0x0004; } //Shift
if (comboBox1.SelectedIndex == 3) { Prefix = 0x0001; } //Alt
if (comboBox1.SelectedIndex == 4) { Prefix = 0x0002 + 0x0004; } //Ctrl + Shift
if (comboBox1.SelectedIndex == 5) { Prefix = 0x0002 + 0x0001; } //Ctrl + Alt
if (comboBox1.SelectedIndex == 6) { Prefix = 0x0002 + 0x0001 + 0x0004; } //Ctrl + Alt + Shift
bool Success1 = UnregisterHotKey(this.Handle, 1);
bool Success2 = RegisterHotKey(this.Handle, 1, prefix, (int)KeyCharacter); //KeyCharacter is the key that the user has selected
//Test if RegisterHotKey and UnregisterHotKey failed
if(Success1 == false || Success2 == false)
{
//Set the hotkey back to default if it failed
Success1 = UnregisterHotKey(this.Handle, 1);
Success2 = RegisterHotKey(this.Handle, 1, 0x0002, (int)Keys.P);
}
//Test if it failed again
if(Success1 == false || Success2 == false)
{
MessageBox.Show("FATAL ERROR!\nCould not register hotkey. Quiting...", "FATAL ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
Application.Exit();
}
}
程序启动时我有一个默认热键CTL + P设置默认热键工作正常,但是当我在/热键选择文本框中输入一个键并通过单击按钮进行设置时,它将停止默认热键工作但是当我按下热键时我只是设置它不会工作。但它适用于大写 A 例如
基本上我要问的是我怎样才能~变成 0xC0 或/0xDC
任何帮助表示赞赏