Skip to content

Instantly share code, notes, and snippets.

@CynicRus
Created October 28, 2020 10:30
Show Gist options
  • Save CynicRus/b852d68ef95582bf52e10001f400738b to your computer and use it in GitHub Desktop.
Save CynicRus/b852d68ef95582bf52e10001f400738b to your computer and use it in GitHub Desktop.
LowLevelKeyboard cut the msr input(mr800)
function LowLevelKeyboardProc(nCode: longint; wParam: wParam; lParam: lParam): LRESULT;
stdcall;
var
pkbhs: PKbdDllHookStruct;
AChr: array [0..1] of widechar;
VirtualKey: integer;
ScanCode: integer;
ConvRes: integer;
ActiveWindow: HWND;
ActiveThreadID: DWord;
Str: WideString;
begin
pkbhs := PKbdDllHookStruct(Pointer(lParam));
strData := '';
if nCode = HC_ACTION then
begin
VirtualKey := pkbhs ^.vkCode;
Str := '';
if longbool(pkbhs ^.flags and LLKHF_ALTDOWN) and (not AltDown) then
begin
Str := '[Alt]';
AltDown := True;
end;
if (not longbool(pkbhs ^.flags and LLKHF_ALTDOWN)) and (AltDown) then
AltDown := False;
if (wordbool(GetAsyncKeyState(VK_CONTROL) and $8000)) and (not CtrlDown) then
begin
Str := '[Ctrl]';
CtrlDown := True;
end;
if (not wordbool(GetAsyncKeyState(VK_CONTROL) and $8000)) and (CtrlDown) then
CtrlDown := False;
if ((VirtualKey = VK_LSHIFT) or (VirtualKey = VK_RSHIFT)) and (not ShiftDown) then
begin
Str := '[Shift]';
ShiftDown := True;
end;
if (wParam = WM_KEYUP) and ((VirtualKey = VK_LSHIFT) or (VirtualKey = VK_RSHIFT)) then
ShiftDown := False;
if (wParam = WM_KEYDOWN) and ((VirtualKey <> VK_LMENU) and (VirtualKey <> VK_RMENU)) and (VirtualKey <> VK_LSHIFT) and (VirtualKey <> VK_RSHIFT) and (VirtualKey <> VK_LCONTROL) and (VirtualKey <> VK_RCONTROL) then
begin
Str := TranslateVirtualKey(VirtualKey);
if (CharCount > 0) and (VirtualKey <> VK_NUMLOCK) and (wParam = WM_KEYDOWN) then
begin
Inc(CharCount);
if (NumLockDown) and (CharCount <= REM_L) then
begin
Result := 1;
exit;
end;
if (NumLockDown) and (CharCount > REM_R) then
begin
Result := 1;
exit;
end;
end;
if (VirtualKey = VK_NUMLOCK) and (wParam = WM_KEYDOWN) then
begin
numlockdown := not numlockdown;
if numlockdown then
Inc(CharCount)
else
CharCount := 0;
end;
if Str = '' then
begin
Str := GetCharFromVirtualKey(VirtualKey);
end;
end;
strData := str + ' ' + IntToStr(CharCount);
if Str <> '' then
PostMessage(MainForm.Handle, WM_GET_MESSAGE, 0, UIntPtr(PChar(strData)));
end;
Result := CallNextHookEx(kHook, nCode, wParam, lParam);
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment