I have a file in a user folder for Autokey, that has a function I'd like to call from Autokey scripts. The function uses keyboard.send_key
(and .send_keys
), but Autokey throws the error global name 'keyboard' is not defined
.
In Autokey:
import myfile
time.sleep(.3)
keyboard.send_keys("<shift>+<home>")
time.sleep(.1)
keyboard.send_keys("<ctrl>+x")
time.sleep(.1)
keyboard.send_keys("die('<pre>' . print_r(")
time.sleep(.1)
keyboard.send_keys("<ctrl>+v")
time.sleep(.1)
keyboard.send_keys(", 1));")
myfile.twoStepSave()
In myfile.py:
def twoStepSave():
keyboard.send_keys("<ctrl>+s")
time.sleep(1)
window.activate("File Changed")
time.sleep(0.1)
active_title = window.get_active_title()
if (active_title == "File Changed"):
keyboard.send_key("<enter>")
time.sleep(1)
window.activate("File Already Exists")
time.sleep(0.1)
active_title = window.get_active_title()
if (active_title == "File Already Exists"):
keyboard.send_keys("<alt>+o")
I've seen other questions and answers about other globals, but can't figure out how to access and use keyboard. The script runs fine if I leave the code in the second script inside the AutoKey script. What am I missing that would allow me to use "keyboard" in the second script?