[python-win32] Re: Help on using win32api.SendMessage to send keystrokes

Thomas Heller theller at python.net
Thu Apr 7 08:55:21 CEST 2005


>> ctypes is a wonderful package -- invaluable for someone doing Win32 API
>> work.  Basically, it allows you to call any API in any DLL, as long as
>> you can describe the parameters.
>
> except mapvirtualkey. not that it matters now, anyway, but, behold this:
>
> # ##code:
> from ctypes import *
> import time
>
> sc = windll.user32.MapVirtualKey(0x41, 0)
> print sc
> # ##end code
>
> ###output:
> Traceback (most recent call last):
>   File "C:\Documents and Settings\dfolkins\Desktop\python
> scripts\mapvirtualkey.py", line 4, in ?
>     sc = windll.user32.MapVirtualKey(0x41, 0)
>   File "C:\Python24\Lib\site-packages\ctypes\__init__.py", line 366,
> in __getattr__
>     func = self._StdcallFuncPtr(name, self)
> AttributeError: function 'MapVirtualKey' not found
> ###end output

MapVirtualKey is implemented as unicode and ansi function.  Quote MSDN:
    Function Information

    Minimum DLL Version user32.dll 
    Header Declared in Winuser.h, include Windows.h 
    Import library User32.lib 
    Minimum operating systems Windows 95, Windows NT 3.1 
    Unicode Implemented as ANSI and Unicode versions.  

Which means: Call MapVirtualKeyA for ansi strings, MapVirutalKeyW for
unicode strings.

> so... even though i dont care about mapvirtualkey per se, i wonder
> what gives... any ideas?
>
> and... if anyone ever happens upon a way to hook and inject events
> upstream of directinput in a nice api-like way, please let me know,
> eh? :)
>
> Thank you,
> Daniel, off to learn how to inject dll....

Hehe. Good luck.

Thomas



More information about the Python-win32 mailing list