[code=Delphi(Pascal)]
function KeyboardHookHandler(iCode: Integer;
wParam: WPARAM;
lParam: LPARAM): LRESULT; stdcall; export;
const
_KeyPressMask = $80000000;
var
i:integer;
Key_S:String;
begin
Result := 0;
If iCode < 0 Then
begin
Result := CallNextHookEx(DnfNextHook, iCode, wParam, lParam);
Exit;
end;
{
// 侦测 Ctrl + B 组合键
if ((lParam and _KeyPressMask) = 0) and //(lparam and $80000000= 0) -->down <>0 --> up;
(wParam = Ord('B')) then
begin
Result := 1; end;
} for i:=0 to Key_.Count-1 do
begin
//Key_S[1] 因为ORD()只能读一个字节的英文,所以必须STR的中加上[1]
Key_S:=Key_[i];
if ((lParam and _KeyPressMask) = 0) and //(lparam and $80000000= 0) -->down <>0 --> up;
(wParam = Ord(Key_S[1])) then //这里认的按键只能是大写英文
begin Result := 1;
Do_Skill(Skill_[i]);
end;
end;end;我这里Key_值是一个数组,里面存有按键,根据按键来进行Do_Skill操作按键,现在问题是
为什么我动态的这样写就只能在本窗口有效,但换其他窗口就不能模拟按键操作了.如果我用// 侦测 Ctrl + B 组合键 下的那段代码来进行操作,就可以在任意窗口
但我的按键是不确定的呀.请说说怎么解决
function KeyboardHookHandler(iCode: Integer;
wParam: WPARAM;
lParam: LPARAM): LRESULT; stdcall; export;
const
_KeyPressMask = $80000000;
var
i:integer;
Key_S:String;
begin
Result := 0;
If iCode < 0 Then
begin
Result := CallNextHookEx(DnfNextHook, iCode, wParam, lParam);
Exit;
end;
{
// 侦测 Ctrl + B 组合键
if ((lParam and _KeyPressMask) = 0) and //(lparam and $80000000= 0) -->down <>0 --> up;
(wParam = Ord('B')) then
begin
Result := 1; end;
} for i:=0 to Key_.Count-1 do
begin
//Key_S[1] 因为ORD()只能读一个字节的英文,所以必须STR的中加上[1]
Key_S:=Key_[i];
if ((lParam and _KeyPressMask) = 0) and //(lparam and $80000000= 0) -->down <>0 --> up;
(wParam = Ord(Key_S[1])) then //这里认的按键只能是大写英文
begin Result := 1;
Do_Skill(Skill_[i]);
end;
end;end;我这里Key_值是一个数组,里面存有按键,根据按键来进行Do_Skill操作按键,现在问题是
为什么我动态的这样写就只能在本窗口有效,但换其他窗口就不能模拟按键操作了.如果我用// 侦测 Ctrl + B 组合键 下的那段代码来进行操作,就可以在任意窗口
但我的按键是不确定的呀.请说说怎么解决
而且 Key_S:=Key_[i]; 也被赋值,你这样Ord(Key_S[1])) 写,我不太理解?