// Handle global hotkeys protected override void WndProc(ref Message m) { base.WndProc(ref m); if (m.Msg == 0x0312) { Keys key = (Keys)(((int)m.LParam >> 16) & 0xFFFF); WindowsHelper.KeyModifier modifier = (WindowsHelper.KeyModifier)((int)m.LParam & 0xFFFF); int id = m.WParam.ToInt32(); PasteAction matchedAction = new PasteAction(); foreach (PasteAction action in Global.Actions) { if (action.HotKeyRegistrationID == id) { matchedAction = action; } } if (string.IsNullOrEmpty(matchedAction.Name)) { MessageBox.Show("No action is matched to that hotkey"); this.Close(); return; } if (matchedAction.ID == "{00000000-0000-0000-0000-000000000000}") { openActionPicker(); } else if (matchedAction.ID == "{00000000-0000-0000-0000-000000000001}") { WindowsHelper.SetForegroundWindow(this.Handle); WindowsHelper.ShowWindowAsync(this.Handle, 1); } else { matchedAction.Paste(Global.LastApplications[0].WindowHandle, Global.LastApplications[0].LastActiveWindowMode); } } }
private void btn_Execute_Click(object sender, EventArgs e) { if (dgv_Actions.SelectedRows.Count <= 0) { MessageBox.Show("No action is selected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (dgv_LastApplications.SelectedRows.Count <= 0) { MessageBox.Show("No application is selected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } selectedPasteAction = dgv_Actions.SelectedRows[0].DataBoundItem as PasteAction; Classes.Application selectedApplication = dgv_LastApplications.SelectedRows[0].DataBoundItem as Classes.Application; if (selectedApplication.WindowHandle == IntPtr.Zero) { MessageBox.Show("There is something wrong with the selected application", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } selectedPasteAction.Paste(selectedApplication.WindowHandle, selectedApplication.LastActiveWindowMode); }