模拟按鍵???急啊(50分)

  • 主题发起人 主题发起人 myveremy
  • 开始时间 开始时间
M

myveremy

Unregistered / Unconfirmed
GUEST, unregistred user!
begin
keybd_event(VK_MENU, MapVirtualKey(VK_MENU, 0), 0, 0);
keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), 0, 0);
keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), KEYEVENTF_KEYUP, 0);
keybd_event(VK_MENU, MapVirtualKey(VK_MENU, 0), KEYEVENTF_KEYUP, 0);
end;
這樣只是本程序接收到Alt+Enter,我要讓現在進程里的某個程序接收到這命令???????
 
放入timer
 
h:=FindWindow(nil,'MediaPlayer')//'MediaPlayer'指MediaPlayer窗体的名称。
用PostMessage(h,wm_keydown,VK_MENU,0)......
有wm_keydown就要有wm_keyup,两个过程是独立的。
 
就是用我的程序里發命令過去,別人的程序接收到按鍵就觸發事件.

現在比較難的是:我怎樣發'按鍵'給指定某一個程序/或給當前系統的所有程序都發個過去??????
 
to formality:
是否可以發組合鍵比如(Alt + 9等)
 
這樣可以實現:
在一按扭中: ShellExecute打開某個媒體文件
在另一按扭中給它模拟按鍵:
var
h:Thandle;
begin
h:=FindWindow(nil,'Windows Media Player');
if h<>0 then
begin
SetForegroundWindow(h); ////////·í«eµ¡¤f
keybd_event(VK_MENU, MapVirtualKey(VK_MENU, 0), 0, 0);
keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), 0, 0);
keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), KEYEVENTF_KEYUP, 0);
keybd_event(VK_MENU, MapVirtualKey(VK_MENU, 0), KEYEVENTF_KEYUP, 0);
end;
end;

但是我把兩個按扭合在一起就不行了(能打開,但模拟按鍵沒有反應)????
 
keybd_event(VK_MENU, MapVirtualKey(VK_MENU, 0), KEYEVENTF_KEYDown, 0);
keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), KEYEVENTF_KEYDown, 0);
keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), KEYEVENTF_KEYUP, 0);
keybd_event(VK_MENU, MapVirtualKey(VK_MENU, 0), KEYEVENTF_KEYUP, 0);
这个试试
 
哦,我弄错了,keybd_event 没有 KEYEVENTF_KEYDown
 
keybd_event(VK_MENU,0,0,0);
keybd_event(VK_RETURN,0,0,0);
keybd_event(VK_MENU,0,KEYEVENTF_KEYUP,0);
keybd_event(VK_RETURN,0,KEYEVENTF_KEYUP,0);
这个应该可以了。
 
這樣可以實現:
在一按扭中: ShellExecute打開某個媒體文件
ShellExecute(handle,'open','wmplayer.exe','d:/play.wpl,'',SW_SHOW );
在另一按扭中給它模拟按鍵:
var
h:Thandle;
begin
h:=FindWindow(nil,'Windows Media Player');
if h<>0 then
begin
SetForegroundWindow(h); ////////·í«eµ¡¤f
keybd_event(VK_MENU, MapVirtualKey(VK_MENU, 0), 0, 0);
keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), 0, 0);
keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), KEYEVENTF_KEYUP, 0);
keybd_event(VK_MENU, MapVirtualKey(VK_MENU, 0), KEYEVENTF_KEYUP, 0);
end;
end;

但是我把兩個按扭合在一起就不行了(能打開,但模拟按鍵沒有反應),為怎么啊呀!!!
var
h:Thandle;
begin
ShellExecute(handle,'open','wmplayer.exe','d:/play.wpl,'',SW_SHOW );
h:=FindWindow(nil,'Windows Media Player');
///////在這里我取不到它的handle
if h<>0 then
begin
SetForegroundWindow(h); ////////·í«eµ¡¤f
keybd_event(VK_MENU, MapVirtualKey(VK_MENU, 0), 0, 0);
keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), 0, 0);
keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), KEYEVENTF_KEYUP, 0);
keybd_event(VK_MENU, MapVirtualKey(VK_MENU, 0), KEYEVENTF_KEYUP, 0);
end;
end;
 
再頂一下!!!!!!
 
接受答案了.
 

Similar threads

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