So I want to make a Global hotkey and have Mouse 4 or 5 auto click my mouse.
The way I'm global binding is a bit interesting.
So on the form, I have a label that will set active control when clicked to listen to show what the keybind is when pressed.
private Keys clickerHotkey;
private void leftClickHotkeyLbl_Click(object sender, EventArgs e)
{
this.ActiveControl = leftClickHotkeyLbl; // set active to able to respond to the key down event.
leftClickHotkeyLbl.Text = "[...]";
}
private void leftClickHotkeyLbl_KeyDown(object sender, KeyEventArgs e)
{
leftClickHotkeyLbl.TabStop = false;
if (!((e.KeyValue >= 16 && e.KeyValue <= 18) || (e.KeyValue >= 21 && e.KeyValue <= 25) || (e.KeyValue >= 28 && e.KeyValue <= 31) || e.KeyValue == 229 || (e.KeyValue >= 91 && e.KeyValue <= 92))) // this gets rid of non sense keys...
{
KeyBindManager.KeysConverter.UnregisterHotKey(this.Handle, (int)clickerHotkey); // unregister previous key.
clickerHotkey = e.KeyData;
if (clickerHotkey == Keys.XButton1) // doesn't work :(
{
Console.WriteLine("Mouse 5 Detected");
}
if (clickerHotkey == Keys.Escape) // if the key is escape, return
{
UnsetHotkey(clickerHotkey);
leftClickHotkeyLbl.Text = "[-]";
this.ActiveControl = null;
return;
}
clickerModifiers = ExtractModifier(clickerModifiers, e);
SetHotkey(clickerModifiers, clickerHotkey);
leftClickHotkeyLbl.Text = $"[{KeyBindManager.KeysConverter.Convert(clickerHotkey)}]";
this.ActiveControl = null; // set to null so its no longer being edited.
}
}
Any help is much appreciated! Cheers!