Advertisement

Mouse/Keyboard Macros

Started by February 19, 2001 04:48 PM
2 comments, last by Brett Crain 23 years, 11 months ago
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.
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.

==========================================In a team, you either lead, follow or GET OUT OF THE WAY.
Advertisement
You might want to look into mouse_event and keybd_event. Try the MSDN.

"Finger to spiritual emptiness underlying everything." -- How a C manual referred to a "pointer to void." --Things People Said
http://www.gdarchive.net/druidgames/
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.

This topic is closed to new replies.

Advertisement