[python-win32] Re: Help on using win32api.SendMessage to
sendkeystrokes
Roel Schroeven
rschroev_nospam_ml at fastmail.fm
Sun Apr 3 11:07:56 CEST 2005
Mark Hammond wrote:
> PostMessage wants a Python integer object (or a long that could fit in an
> int). In practice, that means sending a negative integer when you want the
> MSB set.
>
> Sadly (IMO), in Python 2.4, all these bitwise operations have become more
> "pythonic" rather than like C. Thus, in 2.3 and earlier:
>
>
>>>>1<<31
>
> -2147483648
>
> but 2.4+:
>
>
>>>>1<<31
>
> 2147483648L
>
>
>>Would that be a bug in python's implementation of PostMessage,
>>or am i missing something?
>
>
> Many of the pywin32 functions work like this, and will not accept the new
> long value. I beleive that can be fixed fairly easily - but changing the
> return values from these functions would open a can of worms. I'm not sure
> of a clean solution.
One option seems to be to run the desired Python long value trough a
pack and unpack sequence to get the corresponding integer value:
from struct import *
>>> unpack('=l', pack('=L', 0xC0000000))[0]
-1073741824
--
If I have been able to see further, it was only because I stood
on the shoulders of giants. -- Isaac Newton
Roel Schroeven
More information about the Python-win32
mailing list