Kod tego typu również używam w swoim programie do uruchamiania, zatrzymywania schematów oraz dodawania do niego instrukcji.
Kopiuj
procedure TfrmMenu.FormCreate(Sender: TObject);
begin
F1 := GlobalAddAtom('Hotkey1');
F2 := GlobalAddAtom('Hotkey2');
F3 := GlobalAddAtom('Hotkey3');
F4 := GlobalAddAtom('Hotkey4');
F5 := GlobalAddAtom('Hotkey5');
F6 := GlobalAddAtom('Hotkey6');
RegisterHotKey(Handle, F1, 0, VK_F1);
RegisterHotKey(Handle, F2, 0, VK_F2);
RegisterHotKey(Handle, F3, 0, VK_F3);
RegisterHotKey(Handle, F4, 0, VK_F4);
RegisterHotKey(Handle, F5, 0, VK_F5);
RegisterHotKey(Handle, F6, 0, VK_F6);
end;
procedure TfrmMenu.FormDestroy(Sender: TObject);
begin
UnRegisterHotKey(Handle, F1);
UnRegisterHotKey(Handle, F2);
UnRegisterHotKey(Handle, F3);
UnRegisterHotKey(Handle, F4);
UnRegisterHotKey(Handle, F5);
UnRegisterHotKey(Handle, F6);
end;
Niestety nie mogę rejestrować tutaj ALT-a tylko musi on zostać przechwycony w hook-u, który niestety dla tego klawisza nie chce poprawnie działać.
Kopiuj
function KeyboardHookProc(nCode : Integer; wParam : integer; lParam : integer) : Integer; stdcall; export;
var
Hook : PKBDLLHOOKSTRUCT;
NewChar: array [0..1] of Char;
s: String;
begin
Hook := Pointer(lParam);
case nCode of
HC_ACTION :
begin
If not iMoveIt.getConfig.Hook_Paused Then
begin
FillChar(NewChar,2,#0);
GetKeyboardState(KeyState);
iMoveIt.GetDataFromCursor;
case Hook.vkCode of
VK_LSHIFT, VK_RSHIFT, VK_SHIFT:
begin
if FBuffer <> '' then
begin
iMoveIt.AddAction(iMoveIt.getConfig.Action_TypeText, '', 0, 0, FBuffer + '1');
FBuffer := '';
end;
if (wParam = WM_KEYDOWN) then
begin
if not SHIFT_WaitForUp then
begin
Start := GetTickCount;
iMoveIt.AddAction(iMoveIt.getConfig.Action_SpecialKey, '', 0, 0, '[SHIFT DOWN]');
SHIFT_WaitForUp := True;
end;
end else
begin
stop := GetTickCount;
iMoveIt.AddAction(iMoveIt.getConfig.Action_SpecialKey, '', 0, stop - start, '[SHIFT UP]');
SHIFT_WaitForUp := False;
end;
end;
VK_ESCAPE:
begin
if FBuffer <> '' then
begin
iMoveIt.AddAction(iMoveIt.getConfig.Action_TypeText, '', 0, 0, FBuffer + '1');
FBuffer := '';
end;
if (wParam = WM_KEYDOWN) then
begin
if not ESC_WaitForUp then
begin
Start := GetTickCount;
iMoveIt.AddAction(iMoveIt.getConfig.Action_SpecialKey, '', 0, 0, '[ESC DOWN]');
ESC_WaitForUp := True;
end;
end else
begin
stop := GetTickCount;
iMoveIt.AddAction(iMoveIt.getConfig.Action_SpecialKey, '', 0, stop - start, '[ESC UP]');
ESC_WaitForUp := False;
end;
end;
VK_RETURN:
begin
if FBuffer <> '' then
begin
iMoveIt.AddAction(iMoveIt.getConfig.Action_TypeText, '', 0, 0, FBuffer + '1');
FBuffer := '';
end;
if (wParam = WM_KEYDOWN) then
begin
if not ENTER_WaitForUp then
begin
Start := GetTickCount;
iMoveIt.AddAction(iMoveIt.getConfig.Action_SpecialKey, '', 0, 0, '[ENTER DOWN]');
ENTER_WaitForUp := True;
end;
end else
begin
stop := GetTickCount;
iMoveIt.AddAction(iMoveIt.getConfig.Action_SpecialKey, '', 0, stop - start, '[ENTER UP]');
ENTER_WaitForUp := False;
end;
end;
VK_TAB:
begin
if FBuffer <> '' then
begin
iMoveIt.AddAction(iMoveIt.getConfig.Action_TypeText, '', 0, 0, FBuffer + '1');
FBuffer := '';
end;
if (wParam = WM_KEYDOWN) then
begin
if not TAB_WaitForUp then
begin
Start := GetTickCount;
iMoveIt.AddAction(iMoveIt.getConfig.Action_SpecialKey, '', 0, 0, '[TAB DOWN]');
TAB_WaitForUp := True;
end;
end else
begin
stop := GetTickCount;
iMoveIt.AddAction(iMoveIt.getConfig.Action_SpecialKey, '', 0, stop - start, '[TAB UP]');
TAB_WaitForUp := False;
end;
end;
VK_LMENU, VK_RMENU, VK_MENU:
begin
if FBuffer <> '' then
begin
iMoveIt.AddAction(iMoveIt.getConfig.Action_TypeText, '', 0, 0, FBuffer + '1');
FBuffer := '';
end;
if (wParam = WM_KEYDOWN) then
begin
if not ALT_WaitForUp then
begin
Start := GetTickCount;
iMoveIt.AddAction(iMoveIt.getConfig.Action_SpecialKey, '', 0, 0, '[ALT DOWN]');
ALT_WaitForUp := True;
end;
end else
begin
stop := GetTickCount;
iMoveIt.AddAction(iMoveIt.getConfig.Action_SpecialKey, '', 0, stop - start, '[ALT UP]');
ALT_WaitForUp := False;
end;
end;
VK_BACK:
begin
if FBuffer <> '' then
begin
iMoveIt.AddAction(iMoveIt.getConfig.Action_TypeText, '', 0, 0, FBuffer + '1');
FBuffer := '';
end;
if (wParam = WM_KEYDOWN) then
begin
if not BACKSPACE_WaitForUp then
begin
Start := GetTickCount;
iMoveIt.AddAction(iMoveIt.getConfig.Action_SpecialKey, '', 0, 0, '[BACKSPACE DOWN]');
BACKSPACE_WaitForUp := True;
end;
end else
begin
stop := GetTickCount;
iMoveIt.AddAction(iMoveIt.getConfig.Action_SpecialKey, '', 0, stop - start, '[BACKSPACE UP]');
BACKSPACE_WaitForUp := False;
end;
end;
end;
if (wParam = WM_KEYDOWN) then
begin
If ToAscii(Hook^.vkCode,Hook^.scanCode,KeyState,NewChar,0) = 1 Then
FBuffer := FBuffer + NewChar[0];
end;
end;
end;
end;
Result := CallNextHookEx(KeyboardHookHandle, nCode, wParam, lParam);
end;