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: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119:
| ... private Hotkey0_id : Integer; Hotkey1_id : Integer; ....
procedure SendString(AText: String); var lCount : Integer; lScanCode : Smallint; lWithAlt, lWithCtrl, lWithShift : Boolean; begin for lCount := 1 To Length(AText) Do begin lScanCode := VkKeyScan(AText[lCount]); lWithShift := lScanCode and (1 shl 8) <> 0; lWithCtrl := lScanCode and (1 shl 9) <> 0; lWithAlt := lScanCode and (1 shl 10) <> 0;
if lWithShift then keybd_event(VK_SHIFT, 0, 0, 0); if lWithCtrl then keybd_event(VK_CONTROL, 0, 0, 0); if lWithAlt then keybd_event(VK_MENU, 0, 0, 0);
keybd_event(lScanCode, 0, 0, 0); keybd_event(lScanCode, 0, KEYEVENTF_KEYUP, 0);
if lWithAlt then keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0); if lWithCtrl then keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0); if lWithShift then keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0); end; end;
...
procedure ShortCutToHotKey(HotKey: TShortCut; var Key : Word; var Modifiers: Uint); var Shift: TShiftState; begin ShortCutToKey(HotKey, Key, Shift); Modifiers := 0; if (ssShift in Shift) then Modifiers := Modifiers or MOD_SHIFT; if (ssAlt in Shift) then Modifiers := Modifiers or MOD_ALT; if (ssCtrl in Shift) then Modifiers := Modifiers or MOD_CONTROL; end;
...
procedure TFormMain.WMHotKey(var Msg: TWMHotKey); var TypeText : String; i : Integer; begin
if Msg.HotKey = Hotkey0_id then begin TypeText := 'Stringtest'; end;
if Msg.HotKey = Hotkey1_id then begin TypeText := DateTimeToStr( Date() ); end;
SendString(TypeText); end;
...
procedure TFormMain.FormCreate(Sender: TObject); var Key : Word; Modifiers: UINT; begin
TrayIcon1.Visible := True;
ShortCutToHotKey(HotKey0.HotKey, Key, Modifiers); Hotkey0_id := GlobalAddAtom('MyHotKey_0'); RegisterHotKey(Handle, Hotkey0_id, Modifiers, Key);
ShortCutToHotKey(HotKey1.HotKey, Key, Modifiers); Hotkey1_id := GlobalAddAtom('MyHotKey_1'); RegisterHotKey(Handle, Hotkey1_id, Modifiers, Key); end;
...
procedure TFormMain.FormClose(Sender: TObject; var Action: TCloseAction); begin UnRegisterHotKey(Handle, Hotkey0_id); GlobalDeleteAtom(Hotkey0_id);
UnRegisterHotKey(Handle, Hotkey1_id); GlobalDeleteAtom(Hotkey1_id); end; |