1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92:
| using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices;
namespace HotKeys { public partial class Form1 : Form { public Form1() { InitializeComponent(); } [DllImport("user32.dll")] private static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vk);
[DllImport("user32.dll")] private static extern bool UnregisterHotKey(IntPtr hWnd, int id);
const int MOD_CONTROL = 0x0002; const int MOD_SHIFT = 0x0004; const int WM_HOTKEY = 0x0312;
private void button1_Click(object sender, EventArgs e) { label1.Text = "Hallo :D"; }
private void button2_Click(object sender, EventArgs e) { label1.Text = ""; }
private void Form1_Load(object sender, EventArgs e) {
RegisterHotKey(this.Handle, 1, MOD_CONTROL , (int)Keys.X); RegisterHotKey(this.Handle, 2, MOD_CONTROL , (int)Keys.Y); RegisterHotKey(this.Handle, 3, MOD_CONTROL, (int)Keys.Z); RegisterHotKey(this.Handle, 4 ,MOD_CONTROL,(int)Keys.F1); }
private void Form1_FormClosing(object sender, FormClosingEventArgs e) { UnregisterHotKey(this.Handle, 1); }
protected override void WndProc(ref Message m) { if (m.Msg == WM_HOTKEY && (int)m.WParam == 1) { progressBar1.Value=0; MessageBox.Show("Hotkey X erhalten."); }
if (m.Msg == WM_HOTKEY && (int)m.WParam == 2) { progressBar1.Value = 100; MessageBox.Show("Hotkey Y erhalten."); } if (m.Msg == WM_HOTKEY && (int)m.WParam == 3) { MessageBox.Show("Hotkey Z erhalten."); } if (m.Msg == WM_HOTKEY && (int)m.WParam == 4) { MessageBox.Show("Hotkey F1 erhalten."); } base.WndProc(ref m);
} } } |