Hi All,
I am trying to create a custom keyboard driver program(like
http://www.tavultesoft.com/keyman/ ) for windows using python.
If this python script is run in the background, what is typed should be
converted into my native language.
For example if I hit 'a' in the keyboard, the output of the keyboard should
be a tamil unicode character(which will be pre-defined by user).

For making such program, i tried exploring pyHook based on this tutorial.
http://mindtrove.info/articles/monitoring-global-input-with-pyhook/

>From the tutorial, I have learned to capture the keys typed, but couldn't
understand how to change the keys before they reach the windows
applications.

Attached is the sample code I used (In this code basically i am trying to
change all the keys typed to 'b' in this code, but its not working )

Please guide me on how i can change the keys sent to the application using
pyHook. Or is there any other library that I can make use of to create such
application.

Regards,
Mugunth

-- 

http://mugunth.blogspot.com
http://thamizha.com
http://tamilblogs.com


-- 
http://webspace2host.com
"Your friendly hosting provider"
import pythoncom, pyHook

def OnKeyboardEvent(event):
  # Change all the keys and make them equal to b
  event.__setattr__('key', 'B') 
  event.__setattr__('Ascii', 98) 
  event.__setattr__('ScanCode', 48) 
  event.__setattr__('KeyID', 66) 
  print '-----------------'
  #print event.Key
  print 'MessageName:',event.MessageName
  print 'Message:',event.Message
  print 'Time:',event.Time
  print 'Window:',event.Window
  print 'WindowName:',event.WindowName
  print 'Ascii:', event.Ascii, chr(event.Ascii)
  print 'Key:', event.Key
  print 'KeyID:', event.KeyID
  print 'ScanCode:', event.ScanCode
  print 'Extended:', event.Extended
  print 'Injected:', event.Injected
  print 'Alt', event.Alt
  print 'Transition', event.Transition
  print '-----------------'
  print '-----------------'
  return True
  #return (event.Ascii not in (ord('a'), ord('A')))

# create a hook manager
hm = pyHook.HookManager()
# watch for all mouse events
hm.KeyDown = OnKeyboardEvent
# set the hook
hm.HookKeyboard()
# wait forever
pythoncom.PumpMessages()
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to