Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; LAST UPDATED 11-May-2019
- ; Changelog
- ; 11-05-2019
- ; - hold keys no longer repeat input upon alternate key activation
- #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
- ; #Warn ; Enable warnings to assist with detecting common errors.
- SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
- SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
- #SingleInstance
- #Persistent
- #KeyHistory 0
- ; ===============================================
- ; >>>>>>>>>>>>> SETTINGS <<<<<<<<<<<<<
- ; change these to your liking
- ; ===============================================
- global AlternateFunctionActivationDelay := 250 ; time in miliseconds (1000 = 1 second)
- ; ===============================================
- ; >>>>>>>>>>>>> TIPS AND NOTES <<<<<<<<<<<<<
- ; ===============================================
- ; $ sign before hotkey allows us to use the key bound to the hotkey in the function it invokes
- ; ~ sign does what $ sign does while also activating this key as if it was not a hotkey
- ;
- ; ^ sign is for CONTROL modifier key
- ; + sign is for SHIFT modifier key
- ; ! sign is for ALT modifier key
- ; ===============================================
- ; >>>>>>>>>>>>> KEY MAPPINGS - HOTKEYS <<<<<<<<<<<<<
- ; change these to your liking
- ; ===============================================
- ; add second row of function keys to F1 - F6
- $F1::TryToActivateAlternateKeyOnHold("F1", "", "{F7}", AlternateFunctionActivationDelay)
- $F2::TryToActivateAlternateKeyOnHold("F2", "", "{F8}", AlternateFunctionActivationDelay)
- $F3::TryToActivateAlternateKeyOnHold("F3", "", "{F9}", AlternateFunctionActivationDelay)
- $F4::TryToActivateAlternateKeyOnHold("F4", "", "{F10}", AlternateFunctionActivationDelay)
- $F5::TryToActivateAlternateKeyOnHold("F5", "", "{F11}", AlternateFunctionActivationDelay)
- $F6::TryToActivateAlternateKeyOnHold("F6", "", "{F12}", AlternateFunctionActivationDelay)
- ; XButton1 corresponds to "back" key on some computer mice
- $-::TryToActivateAlternateKeyOnHold("-", "", "{XButton1}", AlternateFunctionActivationDelay)
- ; XButton2 corresponds to "forward" key on some computer mice
- $=::TryToActivateAlternateKeyOnHold("=", "", "{XButton2}", AlternateFunctionActivationDelay)
- ; maps L3 and R3 buttons (bumpers) as volume keys when GPD WIN is in mouse input mode
- ; useful as MP3 player shortcut when GPD WIN is closed
- ; warning: this locks these keys for normal usage
- ; -----------------
- Numpad1::Volume_Down
- Numpad2::Volume_Up
- ; Numpad1::Volume_Mute
- ; Numpad2::Media_Play_Pause
- ; alternative ways to set volume
- ; Numpad1::SoundSet, -5
- ; Numpad2::SoundSet, +5
- ; Numpad1::SoundSet, 50
- ; Using Alt-Tab shortcut on Polish keyboard is troublesome due to Right Alt being AltGr (which is Ctrl + Alt)
- ; This makes the Alt-Tab window not disappear automatically after you let got of the shortcut keys
- ; This line fixes that.
- RAlt & Tab::AltTab
- ; ===============================================
- ; >>>>>>>>>>>>> VARIABLES <<<<<<<<<<<<<
- ; ===============================================
- global WasPassthroughActivated
- global LastHotkeyPressTime
- global CachedInputActivationKey := "F1"
- global CachedAlternateKeyToActivate
- global CachedActivationHoldDelayTime
- global IsAlternateInputLocked
- ; ===============================================
- ; >>>>>>>>>>>>> FUNCTIONS <<<<<<<<<<<<<
- ; ===============================================
- LockInputTimer()
- {
- if (GetKeyState(CachedInputActivationKey, "P") == false)
- {
- IsAlternateInputLocked := false
- SetTimer, LockInputTimer, Off
- }
- }
- TryToActivateAlternateKeyOnHold(functionKeyName, modifiers, secondaryFunctionKey, holdTime, inputKeyPassthrough := false)
- {
- if (IsAlternateInputLocked == true)
- {
- return
- }
- IsAlternateInputLocked := false
- LastHotkeyPressTime := A_TickCount
- ; if inputKeyPassthrough is on, activate the input key once on start
- if (inputKeyPassthrough == true)
- {
- SendInput, %modifiers%{%functionKeyName%}
- }
- ; pass input as normal if allowActivatorInput is on
- WasPassthroughActivated := inputKeyPassthrough
- CachedInputActivationKey := functionKeyName
- CachedAlternateKeyToActivate := secondaryFunctionKey
- CachedActivationHoldDelayTime := holdTime
- if (GetKeyState(CachedInputActivationKey, "P") == true)
- {
- SetTimer, ActivateAlternateKeysAfterDelayTimer, 1
- }
- }
- ActivateAlternateKeysAfterDelayTimer()
- {
- ; cancel alternate input if activator key is not held anymore
- while (A_TickCount - LastHotkeyPressTime < CachedActivationHoldDelayTime)
- {
- if (GetKeyState(CachedInputActivationKey, "P") == false && WasPassthroughActivated == false)
- {
- SendInput, {%CachedInputActivationKey%}
- SetTimer, ActivateAlternateKeysAfterDelayTimer, Off
- return
- }
- }
- ; if the activator key is still pressed, we want the secondary key function
- if (GetKeyState(CachedInputActivationKey, "P") == true)
- {
- SendInput, %CachedAlternateKeyToActivate%
- IsAlternateInputLocked := true
- SetTimer, LockInputTimer, 5
- }
- ; disable timer to prevent looping
- SetTimer, ActivateAlternateKeysAfterDelayTimer, Off
- return
- }
- ; ===============================================
- ; >>>>>>>>>>>>> OTHER - REGIONAL <<<<<<<<<<<<<
- ; ===============================================
- ; NON-ENGLISH LANGUAGES IMPROVEMENTS (POLISH IN THIS CASE)
- ; LOWERCASE - polish characters on-key-hold
- ; $e::TryToActivateAlternateKeyOnHold("e", "", "{Backspace 1}^!{e}", AlternateFunctionActivationDelay, true)
- ; $o::TryToActivateAlternateKeyOnHold("o", "", "{Backspace 1}^!{o}", AlternateFunctionActivationDelay, true)
- ; $a::TryToActivateAlternateKeyOnHold("a", "", "{Backspace 1}^!{a}", AlternateFunctionActivationDelay, true)
- ; $s::TryToActivateAlternateKeyOnHold("s", "", "{Backspace 1}^!{s}", AlternateFunctionActivationDelay, true)
- ; $l::TryToActivateAlternateKeyOnHold("l", "", "{Backspace 1}^!{l}", AlternateFunctionActivationDelay, true)
- ; $z::TryToActivateAlternateKeyOnHold("z", "", "{Backspace 1}^!{z}", AlternateFunctionActivationDelay, true)
- ; $x::TryToActivateAlternateKeyOnHold("x", "", "{Backspace 1}^!{x}", AlternateFunctionActivationDelay, true)
- ; $c::TryToActivateAlternateKeyOnHold("c", "", "{Backspace 1}^!{c}", AlternateFunctionActivationDelay, true)
- ; $n::TryToActivateAlternateKeyOnHold("n", "", "{Backspace 1}^!{n}", AlternateFunctionActivationDelay, true)
- ; UPPERCASE - polish characters on-key-hold
- ; $+e::TryToActivateAlternateKeyOnHold("e", "+", "{Backspace 1}^!+{e}", AlternateFunctionActivationDelay, true)
- ; $+o::TryToActivateAlternateKeyOnHold("o", "+", "{Backspace 1}^!+{o}", AlternateFunctionActivationDelay, true)
- ; $+a::TryToActivateAlternateKeyOnHold("a", "+", "{Backspace 1}^!+{a}", AlternateFunctionActivationDelay, true)
- ; $+s::TryToActivateAlternateKeyOnHold("s", "+", "{Backspace 1}^!+{s}", AlternateFunctionActivationDelay, true)
- ; $+l::TryToActivateAlternateKeyOnHold("l", "+", "{Backspace 1}^!+{l}", AlternateFunctionActivationDelay, true)
- ; $+z::TryToActivateAlternateKeyOnHold("z", "+", "{Backspace 1}^!+{z}", AlternateFunctionActivationDelay, true)
- ; $+x::TryToActivateAlternateKeyOnHold("x", "+", "{Backspace 1}^!+{x}", AlternateFunctionActivationDelay, true)
- ; $+c::TryToActivateAlternateKeyOnHold("c", "+", "{Backspace 1}^!+{c}", AlternateFunctionActivationDelay, true)
- ; $+n::TryToActivateAlternateKeyOnHold("n", "+", "{Backspace 1}^!+{n}", AlternateFunctionActivationDelay, true)
Add Comment
Please, Sign In to add comment