Skip to content

Instantly share code, notes, and snippets.

@Varriount
Created February 1, 2021 02:31
Show Gist options
  • Save Varriount/9143cbc8f1471323ed04d0763a8d79c8 to your computer and use it in GitHub Desktop.
Save Varriount/9143cbc8f1471323ed04d0763a8d79c8 to your computer and use it in GitHub Desktop.
AutoHotkey script to control the keyboard via the mouse.
; MIT License
;
; Copyright (c) 2020 Clay Sweetser
;
; Permission is hereby granted, free of charge, to any person obtaining a copy
; of this software and associated documentation files (the "Software"), to deal
; in the Software without restriction, including without limitation the rights
; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
; copies of the Software, and to permit persons to whom the Software is
; furnished to do so, subject to the following conditions:
;
; The above copyright notice and this permission notice shall be included in all
; copies or substantial portions of the Software.
;
; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
; SOFTWARE.
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn ; Enable warnings to assist with detecting common errors.
#MenuMaskKey vkFF ; Use vkFF to prevent start menu, etc from opening.
#SingleInstance force ; Force a single instance to run.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
SetKeyDelay, 100
; ;; State ;; ;
travelX := 0
travelY := 0
toolTipActive := False
suspended := True
; ;; Functions ;; ;
OnSuspend(){
global
suspended := True
ToolTip,
}
; Resume
OnResume(){
global
suspended := False
UpdateToolTip()
}
; Clear Travel State
ClearTravelState(){
global
; Clear X and Y travel values
travelX := 0
travelY := 0
; Update tooltip
UpdateToolTip()
}
; Reverse Travel State
ReverseTravelState(){
global
Input axis, I L1
; Reverse X and
if (axis = "x") {
travelX *= -1
} else if (axis = "y"){
travelY *= -1
} else if (axis = "r"){
travelX *= -1
travelY *= -1
} else {
MsgBox, % "Invalid reversal input."
}
; Update tooltip
UpdateToolTip()
}
; Repeat Travel State
RepeatTravelState(){
global
MouseMove %travelX%, %travelY%, , R
}
; Travel
Travel(x, y){
global
; Move mouse by the given values, then add the values to the
; amount traveled.
MouseMove %x%, %y%, , R
travelX += x
travelY += y
; Update tooltip
UpdateToolTip()
}
; Travel Left
TravelLeft(){
global
Travel(-1, 0)
}
; Travel Right
TravelRight(){
global
Travel(1, 0)
}
; Travel Up
TravelUp(){
global
Travel(0, -1)
}
; Travel Down
TravelDown(){
global
Travel(0, 1)
}
; Toggle Tooltip
ToggleTooltip(){
global
if (toolTipActive){
ToolTipOff()
} else {
ToolTipOn()
}
}
; Tooltip On
TooltipOn(){
global
toolTipActive := True
UpdateToolTip()
}
; Tooltip Off
TooltipOff(){
global
toolTipActive := False
ToolTip,
}
; Update Tooltip
UpdateToolTip(){
global
if (toolTipActive = True){
ToolTip, % travelX . ", " . travelY
}
}
; ;; Hotkeys ;; ;
; Suspend/Unsuspend
^!s::Suspend
; Clear Travel Data
c::ClearTravelState()
; Repeat Travel Data
Tab::RepeatTravelState()
; Reverse Travel Data
r::ReverseTravelState()
; Toggle Tooltip
t::ToggleTooltip()
; Mouse Buttons
q::LButton
e::RButton
; Arrow Keys
w::TravelUp()
s::TravelDown()
a::TravelLeft()
d::TravelRight()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment