Skip to content

Instantly share code, notes, and snippets.

@fractalbach
Created November 8, 2017 21:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fractalbach/321844854a2a43ec0216f6856dbabb0c to your computer and use it in GitHub Desktop.
Save fractalbach/321844854a2a43ec0216f6856dbabb0c to your computer and use it in GitHub Desktop.
Custom Keyboard shortcut shell script, drag and drop mouse clicking with a keyboard key!
#!/bin/bash
# xinput --list to identify the different input devices availiable to you.
# xinput query-state [device] where the device is a keyboard. Returns all the keys' states.
# xdotool mousedown 1 automates holding down the left mouse click.
# xdotool mouseup 1 automates releasing the left mouse click.
# This program begins by checking if the keyboard button is pressed at the time of its execution.
# If the keyboard button is in the DOWN position, then "press down" the mouse left click.
# wait for a bit (but not too long!), and then check the keyboard position again.
# Once the keyboard button has been released, break out of the loop, and "release" the mouse left click!
if [ $(xinput query-state 13 | grep 'key\[49' | sort) = "key[49]=down" ]; then
xdotool mousedown 1
while [ $(xinput query-state 13 | grep 'key\[49' | sort) = "key[49]=down" ]; do
sleep 0.1
xdotool key --repeat-delay DELAY 100
done
fi
xdotool mouseup 1
@fractalbach
Copy link
Author

xdotool key --repeat-delay DELAY 100 was added in to prevent the actual keypress from continuing. For example, It prevents you from typing "aaaaaaaaaaaaaaaaaaaaaaaaaaaa" while holding down a key.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment