private PSHotKeyManager() { // the powershell window may not actually be focused when // this cmdlet is run so derive the window handle from the PID. Process self = Process.GetCurrentProcess(); _owner = self.MainWindowHandle; _pid = self.Id; _keyHandler = new PSEventingKeyHandler(true); }
private void KeyListener() { EventHandler idleHandler = new EventHandler(Application_Idle); Application.Idle += idleHandler; try { // hook using (PSEventingKeyHandler keyHandler = new PSEventingKeyHandler(true)) { // start a message loop Application.Run(); } // unhook (same thread) } finally { Application.Idle -= idleHandler; } }