> -----Original Message-----
> From: dir...@li...
> [mailto:dir...@li...]
> On Behalf Of Skepsis
> Sent: 29. marraskuuta 2007 21:30
> To: dir...@li...
> Subject: [DirectPython] Sending keys
>
> Hello, I just need a quick answer before proceeding further...
>
> Is it possible to send virtual key strokes with directpython
> to a window so I can finish a voice control program i'm
> writing in Pyhton?
>
> Cheers!
> Adrian Smith
>
Hi,
It is not supported by DirectPython, but you can do it if you have ctypes
installed (Python 2.5 has it by default).
See http://msdn2.microsoft.com/en-us/library/ms646310.aspx for MSDN
documentation about SendInput(). It looks more complicated than it really
is, but some basic ctypes tutorials should be enough to understand it if you
are not familiar with C or C++.
You need to declare some structures and understand what they represent. You
probably only care about the INPUT and KEYBDINPUT structures, but you have
to declare MOUSEINPUT and HARDWAREINPUT (because of the union in INPUT)
altough you don't need to know much about those two.
Alternatively you can use PostMessage() (with ctypes), but that is not
reliable. But if you just hacking something together, it might be enough.
Just don't use it in real production code. However, before you can use that
you must figure out what your target window is. Get the handle by using
FindWindow() (ctypes again) or something similar.
You can also use Win32 Extensions for Python (win32all) to access these
functions. It is easier, but you need to download additional packages.
As you can see, there are many ways to archieve what you ask. Check them out
before you decide.
--
Heikki Salo
|