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

Re: [pygame] full keyboard control



Yep. That was the quick and dirty way.

On Tue, Apr 8, 2008 at 1:22 PM, Brian Fisher <brian@xxxxxxxxxxxxxxxxxxx> wrote:
> doesn't that code block tab entirely? as opposed to just alt-tab?
>
>
>
>  On Tue, Apr 8, 2008 at 11:24 AM, Brian Davis <intrepidhero@xxxxxxxxx> wrote:
>  > pyHook looks to be the way to go. I just posted a recipe to the ASPN
>  >  cookbook that is basically the example Brian F. linked to above with a
>  >  few mods to block the windows key and alt-tab and use the pygame event
>  >  pump. No matter what you do pyHook won't block the ctrl-alt-del
>  >  combination which seems like a good thing.
>  >
>  >  Here's the link to the recipe:
>  >  http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/553270
>  >  And the code if that link doesn't work:
>  >  import pyHook
>  >  import pygame
>  >
>  >  # create a keyboard hook
>  >  def OnKeyboardEvent(event):
>  >         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 '---'
>  >         if event.Key.lower() in ['lwin', 'tab', 'lmenu']:
>  >                 return False    # block these keys
>  >         else:
>  >                 # return True to pass the event to other handlers
>  >                 return True
>  >
>  >  # create a hook manager
>  >  hm = pyHook.HookManager()
>  >  # watch for all keyboard events
>  >  hm.KeyDown = OnKeyboardEvent
>  >  # set the hook
>  >  hm.HookKeyboard()
>  >
>  >  # initialize pygame and start the game loop
>  >  pygame.init()
>  >
>  >  while(1):
>  >         pygame.event.pump()
>  >
>  >  Thanks to everbody for the help!
>  >
>  >  -Brian
>  >
>



-- 
Brian Davis
intrepidhero@xxxxxxxxx
davis.brianjames@xxxxxxxxx