Board index » delphi » Best Method to simulate user mouse or keyboard actions

Best Method to simulate user mouse or keyboard actions

I've been writing a blackjack program, and now have it to the
point where it plays well enough via the GUI interface. I now
want to provide an option to have it play itself. I've created
an object that computes the best "action", and am at the point
where I'd like to simulate these actions as if users have clicked
them in, or used keyboard hot-keys to choose actions.

My ideas so far involve two techniques, using the idle loop as the
point of kick-off:
        - write a "sendkey" mechanism and do it all by pushing hot-keys
        onto the message queue. (delphi developers has a sendkey version that
        I can use).
        - Use SetFocus to shift focus to the proper button/control
        for the action and PostMessage of WM_LBUTTONUP message.

However, having very little windows API or event-based programming
experience, I'm looking for validation or other ideas. Will one of
these work better than another, or is there something easier or better
to do?

TIA - jubal

ju...@sequent.com

 

Re:Best Method to simulate user mouse or keyboard actions


JK>I've been writing a blackjack program, and now have it to the
JK>point where it plays well enough via the GUI interface. I now
JK>want to provide an option to have it play itself. I've created
JK>an object that computes the best "action", and am at the point
JK>where I'd like to simulate these actions as if users have clicked
JK>them in, or used keyboard hot-keys to choose actions.

JK>My ideas so far involve two techniques, using the idle loop as the
JK>point of kick-off:
JK>        - write a "sendkey" mechanism and do it all by pushing hot-keys
JK>        onto the message queue. (delphi developers has a sendkey version tha
JK>        I can use).
JK>        - Use SetFocus to shift focus to the proper button/control
JK>        for the action and PostMessage of WM_LBUTTONUP message.

JK>However, having very little windows API or event-based programming
JK>experience, I'm looking for validation or other ideas. Will one of
JK>these work better than another, or is there something easier or better
JK>to do?

I would recommend using journal playback recors, if the computer
'playing' takes a long time. If you manually emulate the clicks (ie.
send messages to the controls yourself), the user can still play with
the mouse, and probably could mess things up.

If you need examples, I think the Teixera's Delphi book had an example
of this. I'm not sure, but if I'm wrong, hopefully someone can correct
me. BTW, the API help file is worth looking, although there are no
examples.

Regards,

Jani

--
---------------------------------------------------------------------
Jani Jarvinen, Helsinki Finland          jani.jrvi...@hiway.fipnet.fi

Check out Help Editor 2.0 for Windows at:
ftp://ftp.mpoli.fi/metropoli/windows/utils/hlped20.zip

1996: Only four years to computer confusion!
What have you done to avoid it?
---------------------------------------------------------------------
---
 * SLMR 2.1a *

Other Threads