如何获取键盘按键信息并进行比对?(20分)

  • 主题发起人 主题发起人 zbb011
  • 开始时间 开始时间
Z

zbb011

Unregistered / Unconfirmed
GUEST, unregistred user!
比如我想判断用户是不是同时按下了ctrl键和f8键或其他键,当然这个按键的组合可以任意更改了,谁知道怎么做的帮帮忙啊!
 
怎么这个问题没有人会吗?江湖救急,帮帮忙啊!
 
onkeypress中应该可以
 
TYPE
PKBDLLHOOKSTRUCT = ^KBDLLHOOKSTRUCT;
KBDLLHOOKSTRUCT = record
vkCode: DWORD;
ScanCode: DWORD;
Flags: DWORD;
Time: DWORD;
dwExtraInfo: DWORD;
end;

var
hkNTKeyboard: HHOOK;
const
WH_KEYBOARD_LL = 13;
function LowLevelKeyboardFunc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;

procedure TForm1.FormCreate(Sender: TObject);
begin
SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardFunc, HInstance, 0);
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
UnhookWindowsHookEx(hkNTKeyboard);
end;




function LowLevelKeyboardFunc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
var
p: PKBDLLHOOKSTRUCT;
begin
if not (nCode=HC_ACTION) then
begin
Result:=CallNextHookEx(0, nCode, wParam, lParam);
Exit;
end;
case wParam of
WM_KEYDOWN,
WM_SYSKEYDOWN:
begin
p:=PKBDLLHOOKSTRUCT(lParam);
if p^.vkCode = VK_LCONTROL then
SHOWMESSAGE('LEFT CTRL');
end;
WM_KEYUP,
WM_SYSKEYUP:
begin
p:=PKBDLLHOOKSTRUCT(lParam);
if p^.vkCode = VK_LCONTROL then
SHOWMESSAGE('LEFT CTRL');
end;
end;
Result:=CallNextHookEx(0, nCode, wParam, lParam);
end;
 
以上我实验过了,可以的。
 
楼上的高手,可不可以给讲清楚点啊,全是代码,一点注释也没有,看不明白啊?
 
接受答案了.
 
后退
顶部