How to Send F6 with Only a Number Pad (Stupid Python Tricks)
This little script will detect when you hit certain number pad numbers and send the specified function keys on to Windows instead:
import win32com.client
import pythoncom
import pyHook # http://sourceforge.net/projects/uncassist
def translate_keystrokes(event):
if event.Key=='Numpad6': #Next in Screen Saver
print 'You hit numpad 6!'
shell.SendKeys("{F7}")
return False #blocks keystroke
elif event.Key=='Numpad4': #Previous in Screen Saver
print 'You hit numpad 4!'
shell.SendKeys("{F6}")
return False #blocks keystroke
else:
return True #Key stroke continues to Windows apps
#object to let us send keystrokes
shell = win32com.client.Dispatch("WScript.Shell")
# create a hook manager
hm = pyHook.HookManager()
# watch for all keyboard events
hm.KeyDown = translate_keystrokes
# set the hook
hm.HookKeyboard()
# wait forever
pythoncom.PumpMessages()
Why on earth would I want to do this?
Well, this lets me control a screensaver application with a $10 number pad so that the laptop controlling the display can be tucked away out of site. The alternative was to buy this $80 programmable keypad. (If you hadn’t guessed, the screen saver inflexibly requires F6 to move to the next page.)
To make this little script I followed the pyHook examples here. And figured out how to send keystrokes here.
Finally this page gives you a run down on what WScript.Shell does. And this project looks like another promising alternative for sending keystrokes.
Or this $160 much cooler programmable one. Also, I’m terribly sorry about that — it was my fault you had to do this. “I wish I could just push a button to make it change screens.” (in front of Rob)
http://store.artlebedev.com/catalog/computer_add-ons/optimus-mini-three/
That optimus is really cool, Jody. I wish I had seen that one. I didn’t mind doing this, it was a nice holiday project