Re: send keys to focused window

2009-07-13 Thread Lawrence D'Oliveiro
In message mpg.24c0392b71e8a0eb989...@news.bintube.com, Broken wrote:

 I am new to Python, and I'm miserably failing to send specific keys to
 (say) notepad.

I don't understand why you need to automate a GUI front-end, meant for human
use, to a function that can be directly performed without that front-end
anyway.

-- 
http://mail.python.org/mailman/listinfo/python-list


send keys to focused window

2009-07-09 Thread Broken
Hi,
I am new to Python, and I'm miserably failing to send specific keys to 
(say) notepad.

Here is the scenario:
I have notepad open.
My python script is running in the background.
When I press ALT+a I want to intercept the keys and send ä(ASCII code: 
ALT+0228) instead.

OS: Windows 7
Libraries used: pyHook, SendKeys, pyWin32

Here is my code:

###
# -*- coding: cp1252 -*-
import pythoncom, pyHook
from SendKeys import SendKeys

def OnKeyboardEvent(event):
if event.Alt == 32: #alt pressed
if event.Ascii == 97:   #a pressed
SendKeys(ä)
return False #don't pass to other handlers

# return True to pass the event to other handlers
return True

# create a hook manager
hm = pyHook.HookManager()
# watch for all mouse events
hm.KeyDown = OnKeyboardEvent
# set the hook
hm.HookKeyboard()
# wait forever
pythoncom.PumpMessages()

###

It's largely copied from the pyhook example.
My problem is, I need to somehow disable ALT while sonding the key.

Please help :)
-- 
http://mail.python.org/mailman/listinfo/python-list