Skip to content

Instantly share code, notes, and snippets.

@Walcriz
Last active January 26, 2022 16:32
Show Gist options
  • Save Walcriz/e21bce39013d5a4521c04238735f3961 to your computer and use it in GitHub Desktop.
Save Walcriz/e21bce39013d5a4521c04238735f3961 to your computer and use it in GitHub Desktop.
A very simple AHK script that makes zooming with a tablet in aseprite much better
; Very simple AHK script that makes zooming with a tablet in aseprite much better
; -= How to use this =-
; Ensure you have the "Edit -> Keyboard Shortcuts -> Mouse Wheel -> Zoom with scroll wheel" option enabled else this will NOT work
;
; Hold the 'Z' key and move your mouse/pen in either the X or Y axis (depending what you've set in the config below)
; to adjust the Zoom!
;
; Would recommend to disable the Zoom Tool hotkey inside of Aseprite if you have that set to 'Z'
; -= Credit =-
; Inspired by the https://github.com/arcticnoah/aseprite-brush-size-hotkey ahk script
; Please check it out due to this AHK script taking heavy inspiration from there
; -= Config =-
; when true, it'll check the x axis of the mouse, if false, it'll instead use the y axis
check_x_axis := false
; Invert direction to move cursor in order to zoom in/zoom out
inverted := false
; the time interval for when the mouse position is checked (in milliseconds).
; lower means more sensitive/speedy and higher means less sensitive/speedy
tick_rate = 25
; -= Main Script =-
enable_hotkey := true
holding := false
previous_tick_mouse_pos_x = 0
previous_tick_mouse_pos_y = 0
UpdateZoom()
{
global check_x_axis
global previous_tick_mouse_pos_x
global previous_tick_mouse_pos_y
global inverted
; Check if you're still holding the keybind to make it more responsive
if (!holding)
Return
;
MouseGetPos, current_tick_mouse_pos_x, current_tick_mouse_pos_y
; If is inverted
inverted_value := 0
If inverted {
inverted_value := -1
}
Else {
inverted_value := 1
}
; Mouse position difference since last tick
If check_x_axis {
; Checking X axis
mouse_pos_difference := inverted_value * (current_tick_mouse_pos_x - previous_tick_mouse_pos_x)
}
Else {
; Checking Y axis
mouse_pos_difference := inverted_value * (current_tick_mouse_pos_y - previous_tick_mouse_pos_y)
}
If (mouse_pos_difference != 0 && mouse_pos_difference > 0) {
; Mouse position has increased, decrease zoom (The reverse if the 'inverted' configuration is enabled)
Send {CTRL}{WheelDown}
}
Else If (mouse_pos_difference != 0 && mouse_pos_difference < 0) {
; Mouse position has decreased, increase zoom (The reverse if the 'inverted' configuration is enabled)
Send {CTRL}{WheelUp}
}
}
; CTRL + ALT + Z shortcut to toggle pause the script's functionality
#IfWinActive ahk_exe Aseprite.exe
^!z up::
global enable_hotkey
global holding
holding := false
enable_hotkey := !enable_hotkey
Return
; You can change this key to whatever you want, just make sure to change it on line 75 and 106 as well
#IfWinActive ahk_exe Aseprite.exe
$z::
global enable_hotkey
If (enable_hotkey) {
MouseGetPos, previous_tick_mouse_pos_x, previous_tick_mouse_pos_y
; Send the key input as per usual, ensures typing isn't delayed
SendInput {Text}z
holding := true
; Start check loop
loop {
Sleep, %tick_rate%
checkMousePos()
if (!holding)
Return
}
}
Return
; Disable zooming.
$z up::
global holding
holding := false
Return
; Check mouse and update zoom.
checkMousePos() {
global previous_tick_mouse_pos_x
global previous_tick_mouse_pos_y
UpdateZoom()
MouseGetPos, local_x, local_y
previous_tick_mouse_pos_x := local_x
previous_tick_mouse_pos_y := local_y
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment