@Jamie - Sorry to butt in, but do you have any idea how to get the scancode while using WH_KEYBOARD_LL?
Let me expand a little. I am trying to create a SHIFT LOCK program.
So far I have this :-
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Windows, Classes, SysUtils, Forms, Controls, Graphics, Dialogs, lcltype,
StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
public
end;
var
Form1: TForm1;
HookHandle:THandle;
OEMScanCode:LParam;
const
WH_KEYBOARD_LL = 13;
implementation
{$R *.lfm}
Function KeyboardHOOK(nCode : integer; aWparam:WPARAM; aLParam:LParam) : LResult; StdCall;
type
PKBDLLHOOKSTRUCT = ^TKBDLLHOOKSTRUCT;
TKBDLLHOOKSTRUCT = packed record
vkCode: DWORD;
scanCode: DWORD;
flags: DWORD;
time: DWORD;
dwExtraInfo: DWORD;
end;
var
LKBDLLHOOKSTRUCT : PKBDLLHOOKSTRUCT;
Begin
case nCode of
HC_ACTION :
begin
LKBDLLHOOKSTRUCT := PKBDLLHOOKSTRUCT(alParam);
if (LKBDLLHOOKSTRUCT^.vkCode = VK_UP) then
begin
if (awParam=WM_KEYUP) or (awParam = WM_SYSKEYUP) then
begin
keybd_event(LKBDLLHOOKSTRUCT^.vkCode, 0, KEYEVENTF_KEYUP, 0)
end
else
begin
keybd_event(LKBDLLHOOKSTRUCT^.vkCode, 0, 0, 0);
end;
result := 1;
exit;
end;
end;
end;
Result := CallNextHookEx(HookHandle, nCode, awParam, alParam);
end;
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
HookHandle := SetWindowsHookEx(WH_KEYBOARD_LL ,@KeyboardHOOK, Hinstance, 0);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
if (HookHandle <> 0) then
begin
UnhookWindowsHookEx(HookHandle);
HookHandle := 0;
end;
end;
end.
The first problem I have is that I can't differentiate between the keyboard and keypad.
(I don't to return ! when I press 1 on the keypad)
Thanks in advance.