• Advertisement

Archived

This topic is now archived and is closed to further replies.

Mouse/Keyboard Macros

This topic is 6212 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I''m trying to figure out how to simulate user-input (in windows) such as moving the mouse, mouse-clicks, and keyboard-strokes. Thus far, all I''ve been able to figure out is how to move the mouse while the focus is on my program. SetCursorPos(int x, int y); Any information to get me started on this topic would be greatly appreciated... as I''ve been looking all around this weekend with no such luck.

Share this post


Link to post
Share on other sites
Advertisement
If you want to simulate mouse clicks, use the WM_LBUTTONDOWN, WM_RBUTTONDOWN messages.

For key strokes, try WM_KEYDOWN. Go look these up in the docs if you want more info on how to use them.

Share this post


Link to post
Share on other sites
Alright, I''ve been fooling around with sending commands using PostMessage(), however, it seems the only program that understands the messages being sent is my own program.

PostMessage(macroWnd, WM_KEYDOWN, ch, 0);
PostMessage(macroWnd, WM_KEYUP, ch, 0);

Here, macroWnd is a HWND representing the window that will recieve the message. When cycling through the desktop windows, I''ve attempted to send commands to visible windows, but the only program that seems to respond to it is my own. Also, I''m fairly confident macroWnd is pointing to the correct window because in debugging, I''m able to print out approriate window-titles using GetWindowText().

Could this be due to the other programs not processing the WM_KEYDOWN event and getting keyboard input another way? Perhaps I need to send more "persuasive" messages?

Mouse_event() and keybd_event() seem to work just fine... but I''d still like to figure out where I went wrong when using PostMessage(). Simply because I want to send commands to programs that aren''t necessarily in the foreground.

thanks for the help.

Share this post


Link to post
Share on other sites

  • Advertisement