public
Last active

controlling keyboard with Jython

  • Download Gist
keyboard.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
#!/usr/bin/jython
# -*- coding: utf-8 -*-
# Copyright : (c) SAEKI Yoshiyasu
# License : MIT-style license
# <http://www.opensource.org/licenses/mit-license.php>
# last updated: 2011/06/25
 
from java.awt import Robot
from java.awt.event import KeyEvent
import os
 
os.system("""
osascript << EOF
tell application "TextEdit"
activate
end tell
EOF
""")
# == os.system("open /Applications/TextEdit.app")
 
rbt = Robot()
rbt.keyPress(KeyEvent.VK_SHIFT)
rbt.keyPress(KeyEvent.VK_H)
rbt.keyRelease(KeyEvent.VK_H)
rbt.keyRelease(KeyEvent.VK_SHIFT)
rbt.keyPress(KeyEvent.VK_E)
rbt.keyRelease(KeyEvent.VK_E)
rbt.keyPress(KeyEvent.VK_L)
rbt.keyRelease(KeyEvent.VK_L)
rbt.keyPress(KeyEvent.VK_L)
rbt.keyRelease(KeyEvent.VK_L)
rbt.keyPress(KeyEvent.VK_O)
rbt.keyRelease(KeyEvent.VK_O)
rbt.keyPress(KeyEvent.VK_PERIOD)
rbt.keyRelease(KeyEvent.VK_PERIOD)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.