Board index » delphi » Simulating a key press?

Simulating a key press?

How do I go about simulating a keypress so that on an event (button pressed
on a gamepad in this case) the ACTIVE window (NOT MY program) will believe a
key has been pressed?  I've tried mucking about with
SendMessage(HWND_BROADCAST, WM_KEYDOWN, ???, ???), but can't seem to get it
to work.

I've traced the code and have seen that SendMessage IS getting called, and
I've put visible feedback on my form and seen that it IS still polling the
gamepad (using a timer) and updating the display while a different program
is active and my SendMessage is (at the moment) in the same function as the
display update so it must still be getting called.  Now I just need to find
that magic procedure/function call that will actually send the KEYDOWN
message to whatever program is active.

Can anyone help me?

 

Re:Simulating a key press?


You have to use keyb_event and not a WM_KEYDOWN message. You Delphi CD
contains a unit called SndKey32 that already does all the work for you !

Quote
"C-Tzar" <ct...@swbell.net> wrote in message

news:Bxfi7.938$ta7.138518598@newssvr12.news.prodigy.com...
Quote
> How do I go about simulating a keypress so that on an event (button
pressed
> on a gamepad in this case) the ACTIVE window (NOT MY program) will believe
a
> key has been pressed?  I've tried mucking about with
> SendMessage(HWND_BROADCAST, WM_KEYDOWN, ???, ???), but can't seem to get
it
> to work.

> I've traced the code and have seen that SendMessage IS getting called, and
> I've put visible feedback on my form and seen that it IS still polling the
> gamepad (using a timer) and updating the display while a different program
> is active and my SendMessage is (at the moment) in the same function as
the
> display update so it must still be getting called.  Now I just need to
find
> that magic procedure/function call that will actually send the KEYDOWN
> message to whatever program is active.

> Can anyone help me?

Re:Simulating a key press?


I very much appreciate the reply.

Can you tell me any more about using keyb_event?  I can't find any info on
it anywhere including the help files.

I need to be able to send a keydown when the gamepad button goes down and a
keyup when the gamepad button goes up so SndKey32 won't be able to do what I
need.

Quote
"M.H. Avegaart" <avega...@NOSPAMmccomm.nl> wrote in message

news:9mcluc$cda$1@scavenger.euro.net...
Quote
> You have to use keyb_event and not a WM_KEYDOWN message. You Delphi CD
> contains a unit called SndKey32 that already does all the work for you !

> "C-Tzar" <ct...@swbell.net> wrote in message
> news:Bxfi7.938$ta7.138518598@newssvr12.news.prodigy.com...
> > How do I go about simulating a keypress so that on an event (button
> pressed
> > on a gamepad in this case) the ACTIVE window (NOT MY program) will
believe
> a
> > key has been pressed?  I've tried mucking about with
> > SendMessage(HWND_BROADCAST, WM_KEYDOWN, ???, ???), but can't seem to get
> it
> > to work.

> > I've traced the code and have seen that SendMessage IS getting called,
and
> > I've put visible feedback on my form and seen that it IS still polling
the
> > gamepad (using a timer) and updating the display while a different
program
> > is active and my SendMessage is (at the moment) in the same function as
> the
> > display update so it must still be getting called.  Now I just need to
> find
> > that magic procedure/function call that will actually send the KEYDOWN
> > message to whatever program is active.

> > Can anyone help me?

Re:Simulating a key press?


keybd_event is documented in the Win32 Programmer's reference (win32.hlp).
However, I have no idea what the virtual-key code and the hardware scan code
for the gamepad buttons are (maybe you could try GetKeyboardState).

Quote
"C-Tzar" <ct...@swbell.net> wrote in message

news:dsmi7.1413$EE4.161991700@newssvr30.news.prodigy.com...
Quote
> I very much appreciate the reply.

> Can you tell me any more about using keyb_event?  I can't find any info on
> it anywhere including the help files.

> I need to be able to send a keydown when the gamepad button goes down and
a
> keyup when the gamepad button goes up so SndKey32 won't be able to do what
I
> need.

> "M.H. Avegaart" <avega...@NOSPAMmccomm.nl> wrote in message
> news:9mcluc$cda$1@scavenger.euro.net...
> > You have to use keyb_event and not a WM_KEYDOWN message. You Delphi CD
> > contains a unit called SndKey32 that already does all the work for you !

> > "C-Tzar" <ct...@swbell.net> wrote in message
> > news:Bxfi7.938$ta7.138518598@newssvr12.news.prodigy.com...
> > > How do I go about simulating a keypress so that on an event (button
> > pressed
> > > on a gamepad in this case) the ACTIVE window (NOT MY program) will
> believe
> > a
> > > key has been pressed?  I've tried mucking about with
> > > SendMessage(HWND_BROADCAST, WM_KEYDOWN, ???, ???), but can't seem to
get
> > it
> > > to work.

> > > I've traced the code and have seen that SendMessage IS getting called,
> and
> > > I've put visible feedback on my form and seen that it IS still polling
> the
> > > gamepad (using a timer) and updating the display while a different
> program
> > > is active and my SendMessage is (at the moment) in the same function
as
> > the
> > > display update so it must still be getting called.  Now I just need to
> > find
> > > that magic procedure/function call that will actually send the KEYDOWN
> > > message to whatever program is active.

> > > Can anyone help me?

Re:Simulating a key press?


Quote
> However, I have no idea what the virtual-key code and the hardware scan
code
> for the gamepad buttons are (maybe you could try GetKeyboardState).

I'm not sure but I think it is something like the ascii code of the key you
want to simulate,at least in many cases they are equal.

--
Vladimir Alexandrov
<valexand...@hotmail.com>
ICQ # 86729605

Re:Simulating a key press?


AH, I see, you had a typo in the first response.  I was looking for
keyb_event and found nothing, but I DID find a bit on keybd_event, probably
enough to tinker till it works.  Thanks.

As far as the gamepad, it's a homemade adaptor via the parallel port and
I've already got working code to scan that, just needed the keboard
simulation.  =)

Quote
"M.H. Avegaart" <avega...@NOSPAMmccomm.nl> wrote in message

news:9md1gm$1ffk$1@scavenger.euro.net...
Quote
> keybd_event is documented in the Win32 Programmer's reference (win32.hlp).
> However, I have no idea what the virtual-key code and the hardware scan
code
> for the gamepad buttons are (maybe you could try GetKeyboardState).

> "C-Tzar" <ct...@swbell.net> wrote in message
> news:dsmi7.1413$EE4.161991700@newssvr30.news.prodigy.com...
> > I very much appreciate the reply.

> > Can you tell me any more about using keyb_event?  I can't find any info
on
> > it anywhere including the help files.

> > I need to be able to send a keydown when the gamepad button goes down
and
> a
> > keyup when the gamepad button goes up so SndKey32 won't be able to do
what
> I
> > need.

> > "M.H. Avegaart" <avega...@NOSPAMmccomm.nl> wrote in message
> > news:9mcluc$cda$1@scavenger.euro.net...
> > > You have to use keyb_event and not a WM_KEYDOWN message. You Delphi CD
> > > contains a unit called SndKey32 that already does all the work for you
!

> > > "C-Tzar" <ct...@swbell.net> wrote in message
> > > news:Bxfi7.938$ta7.138518598@newssvr12.news.prodigy.com...
> > > > How do I go about simulating a keypress so that on an event (button
> > > pressed
> > > > on a gamepad in this case) the ACTIVE window (NOT MY program) will
> > believe
> > > a
> > > > key has been pressed?  I've tried mucking about with
> > > > SendMessage(HWND_BROADCAST, WM_KEYDOWN, ???, ???), but can't seem to
> get
> > > it
> > > > to work.

> > > > I've traced the code and have seen that SendMessage IS getting
called,
> > and
> > > > I've put visible feedback on my form and seen that it IS still
polling
> > the
> > > > gamepad (using a timer) and updating the display while a different
> > program
> > > > is active and my SendMessage is (at the moment) in the same function
> as
> > > the
> > > > display update so it must still be getting called.  Now I just need
to
> > > find
> > > > that magic procedure/function call that will actually send the
KEYDOWN
> > > > message to whatever program is active.

> > > > Can anyone help me?

Re:Simulating a key press?


AH, I see, you had a typo in the first response.  I was looking for
keyb_event and found nothing, but I DID find a bit on keybd_event, probably
enough to tinker till it works.  Thanks.

As far as the gamepad, it's a homemade adaptor via the parallel port and
I've already got working code to scan that, just needed the keboard
simulation.  =)

Quote
"M.H. Avegaart" <avega...@NOSPAMmccomm.nl> wrote in message

news:9md1gm$1ffk$1@scavenger.euro.net...
Quote
> keybd_event is documented in the Win32 Programmer's reference (win32.hlp).
> However, I have no idea what the virtual-key code and the hardware scan
code
> for the gamepad buttons are (maybe you could try GetKeyboardState).

> "C-Tzar" <ct...@swbell.net> wrote in message
> news:dsmi7.1413$EE4.161991700@newssvr30.news.prodigy.com...
> > I very much appreciate the reply.

> > Can you tell me any more about using keyb_event?  I can't find any info
on
> > it anywhere including the help files.

> > I need to be able to send a keydown when the gamepad button goes down
and
> a
> > keyup when the gamepad button goes up so SndKey32 won't be able to do
what
> I
> > need.

> > "M.H. Avegaart" <avega...@NOSPAMmccomm.nl> wrote in message
> > news:9mcluc$cda$1@scavenger.euro.net...
> > > You have to use keyb_event and not a WM_KEYDOWN message. You Delphi CD
> > > contains a unit called SndKey32 that already does all the work for you
!

> > > "C-Tzar" <ct...@swbell.net> wrote in message
> > > news:Bxfi7.938$ta7.138518598@newssvr12.news.prodigy.com...
> > > > How do I go about simulating a keypress so that on an event (button
> > > pressed
> > > > on a gamepad in this case) the ACTIVE window (NOT MY program) will
> > believe
> > > a
> > > > key has been pressed?  I've tried mucking about with
> > > > SendMessage(HWND_BROADCAST, WM_KEYDOWN, ???, ???), but can't seem to
> get
> > > it
> > > > to work.

> > > > I've traced the code and have seen that SendMessage IS getting
called,
> > and
> > > > I've put visible feedback on my form and seen that it IS still
polling
> > the
> > > > gamepad (using a timer) and updating the display while a different
> > program
> > > > is active and my SendMessage is (at the moment) in the same function
> as
> > > the
> > > > display update so it must still be getting called.  Now I just need
to
> > > find
> > > > that magic procedure/function call that will actually send the
KEYDOWN
> > > > message to whatever program is active.

> > > > Can anyone help me?

Other Threads