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

2005-03-30 Thread Daniel F
Hi,

I am trying to use win32gui.SendMessage API (or PostMessage), and
cannot figure out why
it is not working. I would appreciate any help! Simple test script I
am using is included below.

I am using pywin32-203 and python 2.4, on winxp pro sp2.

I am a total newbie to python, so if this is a really dumb question,
please do not be surprised. :) I thank you all in advance for any help
and guidance you can provide.

Daniel
---
 Script to try to write something down in notepad
import win32api
import win32gui
import win32con
import time

# get the window handle of the blank, minimized notepad window
hwnd = win32gui.FindWindowEx(0, 0, 0, Untitled - Notepad)

# print it just for kicks
print hwnd

win32gui.ShowWindow(hwnd, win32con.SW_SHOWNORMAL)
#this restores the proper window, so we know we have correct handle

#just to give it a little pause
time.sleep(2)

print trying to post message

#try to send it a return key
win32api.SendMessage(hwnd, win32con.WM_KEYDOWN, win32con.VK_RETURN, 0)
win32api.SendMessage(hwnd, win32con.WM_KEYUP, win32con.VK_RETURN, 0)

#the above generates absolutely no effect on the notepad window.
#same effect no matter what vk code i use (e.g. 65 for A, VK_SPACE for
space, etc)

 end of script
___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


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

2005-03-30 Thread Daniel F
Well... i figured it out - turns out sending the keystrokes to the top
window of notepad didnt work, but sending them to the Edit child
window of notepad did the trick.

But this brings me to another question, although of a less urgent
manner. i had to send WM_CHAR messages, rather than WM_KEYDOWN/KEYUP
in order to get it to work. I have nothing against WM_CHAR, as long as
everything works, but i am just curious why i was not able to achieve
the same effect with the WM_KEYDOWN/KEYUP pair? any takers?

Thanks,
Daniel

On Wed, 30 Mar 2005 10:28:36 -0500, Daniel F [EMAIL PROTECTED] wrote:
 Hi,
 
 I am trying to use win32gui.SendMessage API (or PostMessage), and
 cannot figure out why
 it is not working. I would appreciate any help! Simple test script I
 am using is included below.
 
 I am using pywin32-203 and python 2.4, on winxp pro sp2.
 
 I am a total newbie to python, so if this is a really dumb question,
 please do not be surprised. :) I thank you all in advance for any help
 and guidance you can provide.
 
 Daniel
 ---
  Script to try to write something down in notepad
 import win32api
 import win32gui
 import win32con
 import time
 
 # get the window handle of the blank, minimized notepad window
 hwnd = win32gui.FindWindowEx(0, 0, 0, Untitled - Notepad)
 
 # print it just for kicks
 print hwnd
 
 win32gui.ShowWindow(hwnd, win32con.SW_SHOWNORMAL)
 #this restores the proper window, so we know we have correct handle
 
 #just to give it a little pause
 time.sleep(2)
 
 print trying to post message
 
 #try to send it a return key
 win32api.SendMessage(hwnd, win32con.WM_KEYDOWN, win32con.VK_RETURN, 0)
 win32api.SendMessage(hwnd, win32con.WM_KEYUP, win32con.VK_RETURN, 0)
 
 #the above generates absolutely no effect on the notepad window.
 #same effect no matter what vk code i use (e.g. 65 for A, VK_SPACE for
 space, etc)
 
  end of script

___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


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

2005-04-01 Thread Daniel F
Thank you all for your suggestions! Using PostMessage with
WM_KEYDOWN/KEYUP, and creating the lparam bitfield like that, does the
trick quite well. Really appreciate your help! :)

On Apr 1, 2005 12:59 PM, Tim Roberts [EMAIL PROTECTED] wrote:
 On Thu, 31 Mar 2005 21:40:02 -0500, Daniel F [EMAIL PROTECTED] wrote:
 
 Well, i do need a general solution, I was just using notepad as a test
 case... So it's definitely good for me to know about this - thanks!
 But i wonder, isnt there some kind of an upstream event, that could
 be generated and then would automatically generate and propagate all
 of the keydown, char, and keyup events, so i do not have to worry
 about sending all three?
 
 
 
 You might investigate MapVirtualKey, keybd_event, and SendInput.  I have
 no clue whether these are exposed in the Python Win32 extensions.
 Overall, I would guess the three-message parlay is the lowest-impact method.
 
 also, as to roel's earlier post... could I please have some help on
 how to generate a bit field in python, in order to send a well-formed
 lParam to SendMessage, and thus create a well-formed WM_KEYUP/KEYDOWN
 event?
 
 
 Python supports C expressions; you just build it by hand:
 
 bits = 0x800 | 0x0003 | vkKey
 
 Or, if you prefer the bit numbers explicitly:
 
 bits = (2  30) | (3  16) | vkKey
 
 --
 - Tim Roberts, [EMAIL PROTECTED]
   Providenza  Boekelheide, Inc.
 
 ___
 Python-win32 mailing list
 Python-win32@python.org
 http://mail.python.org/mailman/listinfo/python-win32

___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


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

2005-04-02 Thread Daniel F
Wait, spoke a bit too soon. I noticed that you (Tim) apparently missed
a zero in your first method of building the bits (8 with 6 zeros
instead of 7), which generates only a 28bit number, not 32bits. (which
i blindly copy pasted at first...). when i try to make an actual 32bit
value, and then send it to the PostMessage function, i get the
following exception:

win32api.PostMessage(self.subHwnd, win32con.WM_KEYDOWN,
virtualKeyCode, keyDownBits)
OverflowError: long int too large to convert to int

as i understand it, then...  PostMessage expects exactly 32bits... and
my guess is that since python has no unsigned ints, a 32bit value
needs more than 32bits, so python makes it a long, and then
postmessage complains about longs because it expects an int-sized
value. Would that be a bug in python's implementation of PostMessage,
or am i missing something?

btw, postmessage(keydown) works just as well with a 31-bit value... so
i guess i have no problem with this, just asking out of curiosity.

Thanks,
Daniel

On Apr 1, 2005 4:19 PM, Daniel F [EMAIL PROTECTED] wrote:
 Thank you all for your suggestions! Using PostMessage with
 WM_KEYDOWN/KEYUP, and creating the lparam bitfield like that, does the
 trick quite well. Really appreciate your help! :)
 
 On Apr 1, 2005 12:59 PM, Tim Roberts [EMAIL PROTECTED] wrote:
  On Thu, 31 Mar 2005 21:40:02 -0500, Daniel F [EMAIL PROTECTED] wrote:
 
  Well, i do need a general solution, I was just using notepad as a test
  case... So it's definitely good for me to know about this - thanks!
  But i wonder, isnt there some kind of an upstream event, that could
  be generated and then would automatically generate and propagate all
  of the keydown, char, and keyup events, so i do not have to worry
  about sending all three?
  
  
 
  You might investigate MapVirtualKey, keybd_event, and SendInput.  I have
  no clue whether these are exposed in the Python Win32 extensions.
  Overall, I would guess the three-message parlay is the lowest-impact method.
 
  also, as to roel's earlier post... could I please have some help on
  how to generate a bit field in python, in order to send a well-formed
  lParam to SendMessage, and thus create a well-formed WM_KEYUP/KEYDOWN
  event?
  
 
  Python supports C expressions; you just build it by hand:
 
  bits = 0x800 | 0x0003 | vkKey
 
  Or, if you prefer the bit numbers explicitly:
 
  bits = (2  30) | (3  16) | vkKey
 
  --
  - Tim Roberts, [EMAIL PROTECTED]
Providenza  Boekelheide, Inc.
 
  ___
  Python-win32 mailing list
  Python-win32@python.org
  http://mail.python.org/mailman/listinfo/python-win32
 

___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] character to integer

2005-04-04 Thread Daniel F
function ord() would get the int value of the char. and in case you
want to convert back after playing with the number, function chr()
does the trick

 ord('a')
97
 chr(97)
'a'
 chr(ord('a') + 3)
'd'


On Apr 4, 2005 9:16 AM, Chi Tai [EMAIL PROTECTED] wrote:
 Hello,
 
 how can i make an integer value from a character value like this.
 
 string = Hallo
 integerval = string[0]
 i = integerval + 2 #this does not work because integerval is not an
 integer value
 
 i want the in integervalue the intvalue of the hexvalue 0x48 ( the
 character-value of H)
 Is there a simple possibility ?
 
 Chi-Tai
 
 ___
 Python-win32 mailing list
 Python-win32@python.org
 http://mail.python.org/mailman/listinfo/python-win32

___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


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

2005-04-06 Thread Daniel F
 I don't know the answer to this.  Games tend to be straight-to-the-metal
 applications: they don't truck with a lot of filtering and intermediate
 DLLs.  You might be able to use the debug APIs to watch for the loading
 of the DirectInput DLL and insert some manual hooks, but that's a pretty
 high level of guruness.  Google for api dll injection.

wow, that opened up a wealth of info. thanks.  although i hope to
skate by without using it... ;)

 There are some HID filter drivers in the DDK supplied by Microsoft.  As
 a general rule, it is rare to find a publicly-available  third-party
 kernel driver.  There are several reasons for that.  Most drivers are
 written for a specific device, and are not useful in the general case.
 Device-specific drivers often include information that the manufacturer
 considers to be proprietary.  The support burden for a kernel driver is
 much greater than a user-mode app.  And, the investment in creating and
 debugging a driver is so high, that most manufacturers don't want to
 help the competition by providing the labor for free.

interesting... thanks for the info.
___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


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

2005-04-06 Thread Daniel F
 There is module for injection of *python* code in win32 apps.
 
 http://security.opennet.ru/base/patches/1080837482_191.txt.html
 

this looks interesting, i wanted to give it a look, but it seems that
rootkit.com (where the actual package is hosted) is not resolvable
anymore. you dont happen to have the zips handy, do you?
___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] HookMessage failure?

2005-04-06 Thread Daniel F
Hey Mark,
the correct mesage to hook is win32con.WM_LBUTTONDOWN
try it with this one, and see if that works.
-d

On 7 Apr 2005 02:15:41 -, [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
 Hey,
 
 I'm currently trying to detect all clicks to a particular windows 
 application, using win32gui and win32ui.  Right now I'm using EnumWindows() 
 to find the hwnd I want via window title, and then 
 CreateWindowFromHandle(hwnd) to get a PyCWnd object that represents the 
 window.  I then attempt to use HookMessage() to set up a callback for 
 win32con.LBUTTON_DOWN.  However, my callback never gets called.  I know I'm 
 getting the right PyCWnd object, because I can use it to set/get the window 
 title, but for some reason the callback function never gets called.  Any 
 ideas?
 
 Thanks, -Mark
 ___
 Python-win32 mailing list
 Python-win32@python.org
 http://mail.python.org/mailman/listinfo/python-win32

___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Intro and Windows Questions

2005-04-06 Thread Daniel F
Hi Christophe,

I am a newbie to python myself... but i have settled for now on just
using the scite editor (http://www.scintilla.org/SciTE.html) to code
python. like you, i was not impressed with eclipse+pydev, or pythonwin
(and havent even tried all those other ones you mentioned).

scite doesnt have code completion, but it does have automatic syntax
format, block collapse capability, open multiple files in one window
with tabs, and you can run your program from right inside it through a
shortcut (and probably a lot of other useful stuff that i havent
gotten to use yet). i do have to note that i have not done any gui
stuff in python yet, so maybe i will have to start looking for
something else when i do.

maybe not exactly what you were looking for - just sharing my
[admittedly narrow] experience. please feel free to let me know if you
find a really smashing ide, as i would not be averse to using one,
either.

good luck,
-d

On Apr 6, 2005 2:52 PM, Christophe Leske [EMAIL PROTECTED] wrote:
 Hello there,
 my name is Christophe Leske and i am a developer based in Düsseldorf,
 germany. I have a multimedia programming background, but am slowly crawling
 up to RAD development using Python and am therefore looking for a windows
 IDE and GUI Designer.
 
 Now:
 Ideally, I'd like to have an IDE with code completion, yet all the IDEs i
 have seen so far (WingIDE, Komodo, Ecliipse (either as trustudio or the
 Pydev plugin) don't really cut it for me.
 
 Same goes for the Windows GUI Designers (Boa doesn't even work for me, even
 after compilation - hey, i am a beginner...)
 
 So far, i settled for PythonWin, yet am still looking for better
 alternatives.
 Any suggestions? I also know about specialized editors like Crimson or
 ZeusEdit, but i'd rather go with an IDE (if possible).
 Python seems like a mature development tool for me, which is why i am
 wondering that there seems to be no really good IDE that fits me (or am just
 weird? probably...)
 
 My rubberboat is full of eels,
 Christophe Leske
 tel. +49-(0)211 230 99 70
 .:. fürstenwall 157 .:.
 ::: 40215 düsseldorf :::
 ::: germany :::
 http://www.multimedial.de
 
 ___
 Python-win32 mailing list
 Python-win32@python.org
 http://mail.python.org/mailman/listinfo/python-win32

___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


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

2005-04-07 Thread Daniel F
 Unicode Implemented as ANSI and Unicode versions.
 
 Which means: Call MapVirtualKeyA for ansi strings, MapVirutalKeyW for
 unicode strings.

aha! that works. :) never would have guessed just by looking at that
unicode line what it actually means...

  Daniel, off to learn how to inject dll
 
 Hehe. Good luck.

thanks, seems like im gonna need it...

-d
___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


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

2005-04-07 Thread Daniel F
 I have this:
 
 -rw---  1 niki users 1459352 Apr  1  2004 4-04-01/adder-0.3.3-src.zip
 -rw---  1 niki users  137800 Apr  1  2004 4-04-01/adder-0.3.3-win32.zip
 -rw---  1 niki users   69801 Apr  1  2004 4-04-01/adder-manual.zip
 
 Do you want any of them? By e-mail?

yes, please! with my nifty 2g of space from gmail, should be no
problem getting all three of those. :)

thank you,
daniel
___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Python und Hardwaremanagement

2005-04-14 Thread Daniel F
 Many thanks so far for your quick response. Basically what I mean with
 manage your hardware is writing a program that can switch on/off the
 monitor and keyboard as well as setting/change the resolution and frequency.
 Its just for training. 

to play with the monitor settings, check out the following api
functions in the msdn api reference:

changedisplaysettings
enumdisplaysettings

these are wrapped by pywin32, and will allow you to change resolution,
frequency, etc. (dont think you can turn monitor off through these,
but i may be wrong, i havent used these myself...)

as to the keyboard... i dont think you can turn off the keyboard,
but if you want to disable all keyboard input, you can just hook all
messages (use setwindowhookex api, or the pyHook module, which wraps
setwindowhookex and makes things more convenient), and block them.

-d
___
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32