Solved

Simulating Keyboard Input to Another Program w/o Messages

Posted on 2000-03-06
4
319 Views
Last Modified: 2013-12-03
I'm interested in automating the process of logging into a game by simulating keystrokes from the user.

Once the game has started, I can simulate keystrokes with SendMessage or PostMessages.  However, for some reason at the login screens, this does not seem to work. I can send mouseclick messages, but none of my keystrokes are acknowledged.  Is the game using directinput or something?  Is there a mechanism for me to stick things into the keyboard buffer (w/o writing a device driver)?  

My program runs the game as a child process.  Do I have to dig in, find the relevant directx functions and hook them?  (Was hoping it'd be easier than that).


Thanks in advance.
0
Comment
Question by:mrcurious
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 150 total points
ID: 2588790
I assume you're sending the messages to the window that created the login dialog, not the dialog itself - this would result in the behaviour you described...

BTW: You emulate mouse events by using the 'mouse_event()' API, it's designed for this purpose - here's the description from the VC++ docs:

mouse_event    
The mouse_event function synthesizes mouse motion and button clicks.

Windows NT only: This function has been superseded. Use MouseEventEx instead.

VOID mouse_event( DWORD dwFlags,
 // flags specifying various motion/click variants
 
DWORD dx,
 // horizontal mouse position or position change
 
DWORD dy,
 // vertical mouse position or position change
 
DWORD dwData,
 // amount of wheel movement
 
DWORD dwExtraInfo
 // 32 bits of application-defined information
 
);
   


Parameters
dwFlags

A set of flag bits that specify various aspects of mouse motion and button clicking. The bits in this parameter can be any reasonable combination of the following values: Value
 Meaning
 
MOUSEEVENTF_ABSOLUTE
 Specifies that the dx and dy parameters contain normalized absolute coordinates. If not set, those parameters contain relative data: the change in position since the last reported position. This flag can be set, or not set, regardless of what kind of mouse or mouse-like device, if any, is connected to the system. For further information about relative mouse motion, see the following Remarks section.
 
MOUSEEVENTF_MOVE
 Specifies that movement occurred.
 
MOUSEEVENTF_LEFTDOWN
 Specifies that the left button changed to down.
 
MOUSEEVENTF_LEFTUP
 Specifies that the left button changed to up.
 
MOUSEEVENTF_RIGHTDOWN
 Specifies that the right button changed to down.
 
MOUSEEVENTF_RIGHTUP
 Specifies that the right button changed to up.
 
MOUSEEVENTF_MIDDLEDOWN
 Specifies that the middle button changed to down.
 
MOUSEEVENTF_MIDDLEUP
 Specifies that the middle button changed to up.
 
MOUSEEVENTF_WHEEL
 Windows NT only: Specifies that the wheel has been moved, if the mouse has a wheel. The amount of movement is given in dwData
 


The flag bits that specify mouse button status are set to indicate changes in status, not ongoing conditions. For example, if the left mouse button is pressed and held down, MOUSEEVENTF_LEFTDOWN is set when the left button is first pressed, but not for subsequent motions. Similarly, MOUSEEVENTF_LEFTUP is set only when the button is first released.

dx

Specifies the mouse’s absolute position along the x-axis or its amount of motion since the last mouse event was generated, depending on the setting of MOUSEEVENTF_ABSOLUTE. Absolute data is given as the mouse’s actual x-coordinate; relative data is given as the number of mickeys moved. A mickey is the amount that a mouse has to move for it to report that it has moved.

dy

Specifies the mouse’s absolute position along the y-axis or its amount of motion since the last mouse event was generated, depending on the setting of MOUSEEVENTF_ABSOLUTE. Absolute data is given as the mouse’s actual y-coordinate; relative data is given as the number of mickeys moved.

dwData

If dwFlags is MOUSEEVENTF_WHEEL, then dwData specifies the amount of wheel movement. A positive value indicates that the wheel was rotated forward, away from the user; a negative value indicates that the wheel was rotated backward, toward the user. One wheel click is defined as WHEEL_DELTA, which is 120.

If dwFlags is not MOUSEEVENTF_WHEEL, then dwData should be zero.

dwExtraInfo

Specifies an additional 32-bit value associated with the mouse event. An application calls GetMessageExtraInfo to obtain this extra information.
0
 
LVL 3

Expert Comment

by:SamHobbs
ID: 2588850
You say you "simulate keystrokes" but not how. Are you sending WM-CHAR and/or WM_KEYUP and/or WM_KEYDOWN messages, or something else?
0
 
LVL 86

Expert Comment

by:jkr
ID: 2589041
Ooops, I meant 'keybd_event()', of course...
0
 

Author Comment

by:mrcurious
ID: 2590137

Turns out it was my bad.  I used SendMessage instead of PostMessage!  But your information was useful for future reference.  I had no clue about those functions.

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question