[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Intercepting the Keyboard



On 3/7/2012 8:03 PM, Ryan Strunk wrote:
> Hello everyone,
> In creating audio-based games, I'm trying to make my programs work with
> major screen readers. The problem is that the industry leader, JAWS, likes
> to intercept keystrokes sent to the system. This means that if you build
> arrow key use into a pygame program, JAWS gets to your arrow keys first and
> processes them before Pygame can. Unfortunately, cutting out the screen
> reader isn't an option, as it's used to read any game text that might be
> written to the screen.
> I'm curious if anyone has recommendations as to how I could have Pygame or
> Python get to keyboard events before the rest of the system. I have a friend
> who was able to make this happen using C#.net, but I can't even begin to ask
> how or if it's possible to do this using Python.
> Any help you all can provide would be greatly appreciated.
> All the best,
> Ryan
> 
Try using the pyHook. It allows you to catch these events really easily.
It also allows you to shut off keypresses, including ctrl-esc.


from ctypes import windll
import pyHook as pyhook

hardman = pyhook.HookManager()
hardman.KeyDown = [your key handling function here]
hardman.HookKeyboard()