skimwater 我如何判断在一个Form 上按了两个键(如 Ctrl + F12) 等等 我是这样写的 If Msg.Message=wm_keydown Then Begin //(如果按了两个键,我如何判断按了组合件,并记录该组合件的键盘值 End;
lparam:是一个32的二进制数 16~31是如下意思: 16-23 Specifies the scan code. The value depends on the original equipment manufacturer (OEM). 24 Specifies whether the key is an extended key, such as the right-hand ALT and CTRL keys that appear on an enhanced 101- or 102-key keyboard. The value is 1 if it is an extended key; otherwise, it is 0. 25-28 Reserved; do not use. 29 Specifies the context code. The value is always 0 for a WM_KEYDOWN message. 30 Specifies the previous key state. The value is 1 if the key is down before the message is sent, or it is 0 if the key is up. 31 Specifies the transition state. The value is always 0 for a WM_KEYDOWN message. 可以看一下win32API的帮助,加用spy++分析一下你就会清楚了。
procedure TForm1.DoWmKeyDown(var Message: TMessage);message WM_KeyDown; var AKey, CKey : BYTE; begin AKey := GetKeyState(VK_SHIFT); CKey := GetKeyState(VK_CONTROL); Case Message.WParam of VK_UP : begin // Ctrl+[Up Arrow] If (CKey and $80 = $80) then begin ............ end; // Shift + [Up Arrow] if (AKey and $80 = $80) then begin .............. end;
SkimWater 你变的如此的喜欢分,你的答案不是我所真真所想要的在昨天我已基本实现是这样写的 If Msg.Message=wm_keydown Then Begin If (GetKeyState(Vk_Control)<0 ) and (Msg.wparam= Vk_F11) Then Begin //do my something End; End;
Skimwater 我在向你问一个问题在数字键和(!@等一些字符)我如何能够返回是数字键和字符 我是这样写的 if (GetKeyState(VK_Shift) < 0) and (Msg.wParam = 35) Then Begin GetKeyNameText(Msg.lParam, lpszbuf, sizeof(lpszbuf)); Memo1.Lines.Add(IntTostr(Msg.wParam)+Pchar(lpszbuf)); End; 结果当我按 数字键 1和 (Shift+!)时返回的结果是也样 的都是 1
我是这样写的
If Msg.Message=wm_keydown Then
Begin
//(如果按了两个键,我如何判断按了组合件,并记录该组合件的键盘值
End;
16~31是如下意思:
16-23 Specifies the scan code. The value depends on the original equipment manufacturer (OEM).
24 Specifies whether the key is an extended key, such as the right-hand ALT and CTRL keys that appear on an enhanced 101- or 102-key keyboard. The value is 1 if it is an extended key; otherwise, it is 0.
25-28 Reserved; do not use.
29 Specifies the context code. The value is always 0 for a WM_KEYDOWN message.
30 Specifies the previous key state. The value is 1 if the key is down before the message is sent, or it is 0 if the key is up.
31 Specifies the transition state. The value is always 0 for a WM_KEYDOWN message.
可以看一下win32API的帮助,加用spy++分析一下你就会清楚了。
那是两个消息了,必须连续捕捉两个wm_keydown 消息也就是说,第一个wm_keydown 的wparam值若是vk_control则看下一个是否是wm_keydown并判断是否是vk_f12。
需要注意的是,先按住ctrl再按F12,一般会触发多个vk_control的wm_keydown 的消息,要注意排除。对了,你要学会用Delphi自带的工具:WinSight.
var
AKey, CKey : BYTE;
begin
AKey := GetKeyState(VK_SHIFT);
CKey := GetKeyState(VK_CONTROL);
Case Message.WParam of
VK_UP : begin
// Ctrl+[Up Arrow]
If (CKey and $80 = $80) then
begin
............
end;
// Shift + [Up Arrow]
if (AKey and $80 = $80) then
begin
..............
end;
If Msg.Message=wm_keydown Then
Begin
If (GetKeyState(Vk_Control)<0 ) and (Msg.wparam= Vk_F11) Then
Begin
//do my something
End;
End;
我在向你问一个问题在数字键和(!@等一些字符)我如何能够返回是数字键和字符 我是这样写的
if (GetKeyState(VK_Shift) < 0) and (Msg.wParam = 35) Then
Begin
GetKeyNameText(Msg.lParam, lpszbuf, sizeof(lpszbuf));
Memo1.Lines.Add(IntTostr(Msg.wParam)+Pchar(lpszbuf));
End;
结果当我按 数字键 1和 (Shift+!)时返回的结果是也样 的都是 1
得了以后不问你要,你自觉了!
关于你的新问题,不用那么麻烦,keypress事件里捕获的就是按键对应的ASCII码.
你在那里showmessage(key)试试.