Greetings.
I'm making a program that needs to simulate the mouse right button click on the desktop or another program, I tried to use the onmousedown passing the standard parameters and it didn't worked outside the main program, the event is being called, I tested it with a timer and a message, but it don't work on the desktop, do I need to set some special parameters or use some kind of API?
Thanks
Thiago
Comments
[code]
PostMessage(W, WM_RBUTTONDOWN, wParam, lParam);[/code]
W is window hadle to witch you are sending a message.
WM_RBUTTONDOWN is message that is sent. (if you want you can send any other message)
wParam for WM_RBUTTONDOWN message tels witch control key were pressed when the right mouse button was pressed
MK_CONTROL Set if the CTRL key is down.
MK_LBUTTON Set if the left mouse button is down.
MK_MBUTTON Set if the middle mouse button is down.
MK_RBUTTON Set if the right mouse button is down.
MK_SHIFT Set if the SHIFT key is down.
lParam for WM_RBUTTONDOWN message contains X and Y position of cursor when the right mouse button was pressed
xPos = LOWORD(lParam)
yPos = HIWORD(lParam)
Thanks
wParam contains info wich is some thing like (TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
[b]Shift[/b]: TShiftState; X, Y: Integer);) Shift parameter in Delphi mouse events. There are 5 constants wich describes shift states:
MK_CONTROL Set if the CTRL key is down.
MK_LBUTTON Set if the left mouse button is down.
MK_MBUTTON Set if the middle mouse button is down.
MK_RBUTTON Set if the right mouse button is down.
MK_SHIFT Set if the SHIFT key is down.
So, if you want to simulate right mouse button with CTRL key button pressed you set wParam to MK_CONTROL.
I will try to find out how [b]CreateProcess[/b] and [b]EnumThreadWindows[/b] works so if you need more help don't hastate to ask
Thiago
:
: Thiago
:
Hi... i have learned how CreateProcess works. For example, if you wan to start exe file you write this
[code]
procedure StartExe(aExeFileName: PAnsiChar; R: TProcessInformation;): Boolean;
var
S:TStartupInfo;
begin
FillChar(S,SizeOf(S),0);
FillChar(R,SizeOf(R),0);
S.cb:=SizeOf(S);
Result:=CreateProcess(nil, aExeFileName, nil, nil, False,
CREATE_DEFAULT_ERROR_MODE, nil, nil, S, R);
If Result then WaitForInputIdle(R.hProcess, INFINITE);
end;
[/code]
If exe file was started StartExe will return [b]True[/b] and [b]R[/b] will be filled with process information. There is another way to find thread id. If you know window handle to wich you want to send message you can use this code
[code]
ThreadID:=GetWindowThreadProcessId(WinHandle);
[/code]
When you have thread id you call [b]PostThreadMessage[/b] function. It will send message to the main thread of just started app.
[code]
PostThreadMessage(ThreadId, Message_id, wParam, lParam);
[/code]
I have succeeded to close other apps, to change window names... but key and mouse messages didn't worked. I think that window wich need to recive mouse or key messages must have focus but I still don't know how to do it.
You can try to do this:
[code]
procedure SendMessageToApp(aExeName: PAnsiChar; aMSG:Cardinal; wParam, lParam: Integer);
var P: TProcessInformation;
T: Cardinal;
begin
T:=GetCurrentThreadId;
StartExe(aExeName, R);
AttachThreadInput(T, R.dwThreadId, True);
PostThreadMessage(T, WM_KILLFOCUS, 0, 0);
PostThreadMessage(R.dwThreadId, WM_SETFOCUS, 0, 0);
PostThreadMessage(R.dwThreadId, aMSG, wParam, lParam);
AttachThreadInput(T, R.dwThreadId, False);
end;
[/code]