Browse Source

reorganized library files

ahk-v1
Mario Alegre 5 years ago
parent
commit
23ad7f1940
  1. 115
      lib/HoldRepeat.ahk
  2. 22
      lib/Prelude.ahk
  3. 23
      src/Minecraft.ahk

115
lib/General.ahk → lib/HoldRepeat.ahk

@ -1,60 +1,57 @@
; Set default location and name convention for compiled scripts to use ;
;@Ahk2Exe-ExeName %A_MyDocuments%\AutoHotkey\bin\AHK-%A_ScriptName% ; Functions for holding and repeating keys
;
; Install hooks to make sure script can get physical state of keys instead of logical state.
#InstallKeybdHook Hold(Primary, Secondary) {
#InstallMouseHook Send {%Primary% down}
if ( Secondary.Length() != 0 ) {
; Settings ThisLoop := Func("HoldLoop").bind(Primary,Secondary)
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. SetTimer, %ThisLoop%, 50
SendMode Input ; Recommended for new scripts due to its superior speed and reliability. }
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory. }
#UseHook ; All hotkeys are implemented through keyboard hook to avoid script activating itself.
#MenuMaskKey vkFF HoldLoop(Primary, Secondary) {
if GetKeyState(Primary,"P") {
; SetTimer, , Delete
; Function definitions }
; for index,key in Secondary {
if GetKeyState(key,"P") {
Hold(Primary, Secondary) { Send {%Primary% up}
Send {%Primary% down} SetTimer, , Delete
if ( Secondary.Length() != 0 ) { }
ThisLoop := Func("HoldLoop").bind(Primary,Secondary) }
SetTimer, %ThisLoop%, 50 }
}
} Repeat(Primary, Secondary) {
Send {%Primary% up}
HoldLoop(Primary, Secondary) { Sleep 100
if GetKeyState(Primary,"P") { RepeatVar := 0
SetTimer, , Delete Loop {
} if GetKeyState(Primary,"P") {
for index,key in Secondary { return
if GetKeyState(key,"P") { }
Send {%Primary% up} for index,key in Secondary {
SetTimer, , Delete if GetKeyState(key,"P") {
} return
} }
} }
if (RepeatVar == 2) {
Repeat(Primary, Secondary) { SendEvent, {%Primary%}
Send {%Primary% up} RepeatVar := 1
Sleep 100 } else {
RepeatVar := 0 RepeatVar++
Loop { }
if GetKeyState(Primary,"P") { Sleep 50
return }
} }
for index,key in Secondary {
if GetKeyState(key,"P") { ; Sets key to hold if single tap, or repeat if double tap
return HoldOrRepeat(Primary, Secondary) {
} Send {%Primary% down}
} KeyWait, %Primary%, D, T0.2
if (RepeatVar == 2) { if (ErrorLevel = 0) {
SendEvent, {%Primary%} Repeat(Primary,Secondary)
RepeatVar := 1 } else {
} else { Hold(Primary,Secondary)
RepeatVar++ }
}
Sleep 50
}
} }

22
lib/Prelude.ahk

@ -0,0 +1,22 @@
;
; General Settings
;
; Set default location and name convention for compiled scripts to use
;@Ahk2Exe-ExeName %A_MyDocuments%\AutoHotkey\bin\AHK-%A_ScriptName%
; Install hooks to make sure script can get physical state of keys instead of logical state.
#InstallKeybdHook
#InstallMouseHook
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
; All hotkeys are implemented through keyboard hook to avoid script activating itself.
#UseHook
; MenuMaskKey is set to a virtual key that is defined by Windows as doing nothing
#MenuMaskKey vkFF

23
src/Minecraft.ahk

@ -5,8 +5,9 @@
; Front Matter ; Front Matter
; ;
; Include general library ; Include relevant libraries
#Include ../lib/General.ahk #Include ../lib/Prelude.ahk
#Include ../lib/HoldRepeat.ahk
; Only do hotkeys if relevant window is active ; Only do hotkeys if relevant window is active
#If WinActive("Minecraft") #If WinActive("Minecraft")
@ -20,22 +21,8 @@
; Hold/Autoclick mouse buttons ; Hold/Autoclick mouse buttons
; Holds if single click, autoclicks if double click ; Holds if single click, autoclicks if double click
Tab & LButton UP:: Tab & LButton UP::HoldOrRepeat("LButton",["RButton","MButton"])
KeyWait, LButton, D, T0.2 Tab & RButton UP::HoldOrRepeat("RButton",["LButton","MButton"])
if (ErrorLevel = 0) {
Repeat("LButton",["RButton","MButton"])
} else {
Hold("LButton",["RButton","MButton"])
}
return
Tab & RButton UP::
KeyWait, RButton, D, T0.2
if (ErrorLevel = 0) {
Repeat("RButton",["LButton","MButton"])
} else {
Hold("RButton",["LButton","MButton"])
}
return
; Autorun ; Autorun
Tab & w UP::Hold("w",["s"]) Tab & w UP::Hold("w",["s"])

Loading…
Cancel
Save