Skip to content

Instantly share code, notes, and snippets.

@ChunMinChang
Last active January 13, 2016 08:33
Show Gist options
  • Save ChunMinChang/5df91b4d07ccd8016499 to your computer and use it in GitHub Desktop.
Save ChunMinChang/5df91b4d07ccd8016499 to your computer and use it in GitHub Desktop.
Simulate hardware keyboard input
#!/bin/bash
# Get the simulated key
KEY=$1
#print variable on a screen
echo "Send heardware key '$KEY'"
case "$OSTYPE" in
darwin*)
echo "OSX"
# osascript -e 'tell application System Events" to key code 0'
# osascript -e 'tell application "System Events" to keystroke "a"'
osascript -e 'tell application "System Events" to keystroke "'$KEY'"'
;;
linux*)
echo "LINUX"
# Rely on 'xdotool':
# You should install it by 'sudo apt-get install xdotool'
xdotool key $KEY
;;
solaris*) echo "SOLARIS" ;;
bsd*) echo "BSD" ;;
*) echo "unknown: $OSTYPE" ;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment