G2A Many GEOs
SHARE
TWEET

Global Hotkey Class for C#

a guest Jul 6th, 2010 3,681 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Windows.Forms;
  3. using System.Runtime.InteropServices;
  4.  
  5. namespace Hotkeys
  6. {
  7.     public class GlobalHotkey
  8.     {
  9.         private int modifier;
  10.         private int key;
  11.         private IntPtr hWnd;
  12.         private int id;
  13.  
  14.         public GlobalHotkey(int modifier, Keys key, Form form)
  15.         {
  16.             this.modifier = modifier;
  17.             this.key = (int)key;
  18.             this.hWnd = form.Handle;
  19.             id = this.GetHashCode();
  20.         }
  21.  
  22.         public bool Register()
  23.         {
  24.             return RegisterHotKey(hWnd, id, modifier, key);
  25.         }
  26.  
  27.         public bool Unregiser()
  28.         {
  29.             return UnregisterHotKey(hWnd, id);
  30.         }
  31.  
  32.         public override int GetHashCode()
  33.         {
  34.             return modifier ^ key ^ hWnd.ToInt32();
  35.         }
  36.  
  37.         [DllImport("user32.dll")]
  38.         private static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vk);
  39.  
  40.         [DllImport("user32.dll")]
  41.         private static extern bool UnregisterHotKey(IntPtr hWnd, int id);
  42.     }
  43. }
RAW Paste Data
Ledger Nano X - The secure hardware wallet
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top