用WinIO.dll模拟按键时怎么模拟Ctrl+Enter这样的复合键?(100分)

  • 主题发起人 主题发起人 泥头车
  • 开始时间 开始时间

泥头车

Unregistered / Unconfirmed
GUEST, unregistred user!
在用WinIo模拟按键时,模拟单个键没问题,可模拟象Ctrl+Enter这样的复合键就控制不了了,我是这样写的:
MyKeyDown(VK_CONTROL);
Sleep(50);

MyKeyDown(VK_ENTER);
Sleep(50);
MyKeyUp(VK_ENTER);
Sleep(50);

MyKeyUp(VK_CONTROL);
Sleep(50);
其中MyKeyDown是个按键函数,上面代码执行后,键盘就没法用了,只好注销用户再进入。请问大家碰到过吗,怎么解决的?
 
给你一段模拟特殊按键的代码试试,通过SetShiftState()来做,例如SetShiftState(VK_MENU,TRUE);
procedure KeybdEvent (KeyCode: Byte; Flags: DWORD);
begin
Keybd_Event(KeyCode, MapVirtualKey(KeyCode, 0), Flags, 0);
end;

procedure SetShiftState (Key: Byte; Down: Boolean);
var
KeyState: Boolean;
Flags: DWORD;
begin
KeyState := GetAsyncKeyState(Key) and $8000<>0;
if (KeyState and Down) or ((not KeyState)and(not Down)) then Exit;
if Down then Flags := 0 else Flags := KEYEVENTF_KEYUP;
KeybdEvent(Key,Flags);
end;

procedure SendKey (KeySym: Char; KeyDown: Boolean; bIsWinNT: Boolean);
var
KeyVal: SmallInt;
KeyCode, KeyMask: Byte;
LShift,RShift,Ctrl,Alt, CapsLock: Boolean;
Flags: DWORD;
begin
KeyVal := VkKeyScan(Char(Byte(KeySym) and $FF));
KeyCode := LOBYTE(KeyVal);
KeyMask := HIBYTE(KeyVal);
if KeyCode=$FF then Exit;

CapsLock := (GetAsyncKeyState(VK_CAPITAL) and $8000)<>0;
if CapsLock then KeyMask := KeyMask xor 1;
if bIsWinNT then
begin
LShift := (GetAsyncKeyState(VK_LSHIFT) and $8000) <> 0;
RShift := (GetAsyncKeyState(VK_RSHIFT) and $8000) <> 0;

SetShiftState(VK_RSHIFT, FALSE);
SetShiftState(VK_LSHIFT, FALSE);
SetShiftState(VK_SHIFT, (KeyMask and $01)<>0);

Ctrl := (GetAsyncKeyState(VK_LCONTROL) and $8000) <> 0;
if (not Ctrl) then SetShiftState(VK_LCONTROL,(KeyMask and $02)<>0);
Alt := (GetAsyncKeyState(VK_LMENU) and $8000) <> 0;
if (not Alt) then SetShiftState(VK_LMENU,(KeyMask and $04)<>0);
end else
begin
LShift := (GetAsyncKeyState(VK_SHIFT) and $8000) <> 0;
RShift := FALSE;
SetShiftState (VK_SHIFT, (KeyMask and $01)<>0);
Ctrl := (GetAsyncKeyState(VK_CONTROL) and $8000) <> 0;
if (not Ctrl) then SetShiftState(VK_CONTROL, (Keymask and $02)<>0);
Alt := (GetAsyncKeyState(VK_MENU) and $8000) <> 0;
if (not Alt) then SetShiftState(VK_MENU,(KeyMask and $04)<>0);
end;
if KeyDown then Flags := 0 else Flags := KEYEVENTF_KEYUP;
KeybdEvent(KeyCode and $FF,Flags);

if bIsWinNT then
begin
SetShiftState(VK_LSHIFT, LShift);
SetShiftState(VK_RSHIFT, RSHIFT);
SetShiftState(VK_LCONTROL, CTRL);
SetShiftState(VK_LMENU, ALT);
end else
begin
SetShiftState(VK_SHIFT, LSHIFT);
SetShiftState(VK_CONTROL, CTRL);
SetShiftState(VK_MENU, ALT);
end;
end;
个人认为:自己写代码才是王道,用控件只是辅助。[:)]
 
szhcracker的写的真好,但在很多加了键盘保护的游戏里却不能用呀,Keybd_Event函数不会被执行了,所以还是要WinIO这种驱动级的模拟。
 
我也想知道如何用winio
 
winio是个全局性的摸拟,游戏将无法后台运行,这样的解决方案。。。[:D]
 
再顶起来,看有没有人能回答。
 

Similar threads

I
回复
0
查看
771
import
I
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部