//Fired when a key press is detected by the keyboard hook void onMappedKey(KeyEventArgs e, bool escapeToExit) { if ((int)e.KeyData == keyData) //key pressed is mapped key { Logger.LogDebug("Keyboard hook - Mapped key pressed, stopping emulation"); e.Handled = true; e.SuppressKeyPress = true; int Msg; uint wParam; if (escapeToExit) { //set message to Esc key press Msg = KeyboardHook.WM_KEYDOWN; wParam = KeyboardHook.VK_ESCAPE; } else { //Set message to window close Msg = KeyboardHook.WM_QUIT; wParam = 0; } try { IntPtr wH = proc.MainWindowHandle; if (wH != IntPtr.Zero) { KeyboardHook.PostMessage(wH, Msg, wParam, 0); } } catch (Exception ex) { Logger.LogError("Keyboard hook - error sending close message to emulator - {0}", ex.Message); } } }