Created
January 13, 2016 17:47
-
-
Save adabo/16c7ddbd44322a0c823b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Auto Hold (2015) | |
* by: SoggySocks | |
* version: v0.2.1.1 | |
* | |
* Description: Holds multiple customizable keys or mouse buttons down for any length of time. | |
* User Interface: | |
* Enter key/button | |
* ----------- | |
* Click inside the grey box and press a key or mouse button. You will see | |
* the letters change as you press different keys. | |
* | |
* Sensitivity (In miliseconds) | |
* ----------- | |
* Use this box change the double tap/click sensitivity to your liking. A lower value will | |
* result in fewer accidental double clicks. A higher value will trigger the autohold much | |
* easier but will cause more accidental double clicks (an unwanted experience). | |
* | |
* Add | |
* ----------- | |
* Once your key is entered, press the add button to add it in the list | |
* | |
* Minimize & Close | |
* ----------- | |
* The minimize button will send the window to your tray to reduce clutter on the taskbar. | |
* Right click the green H icon in the tray to show the window or exit the applicaiton. Double | |
* Clicking the icon will show the window too. Simply click the close button to quit the | |
* program and cancel all running hold functions. | |
* | |
* Usage: While in game (currently only 7 Days To Die), double tap or click one of your pre-defined | |
* keys to engage the hold function. To release the hold, press the key/button a single time | |
* to stop it. | |
* WARNING: In my testing, I have found unwanted double clicks can put you in bad positions and kill | |
* the player. Use this program at your OWN RISK. | |
*/ | |
; #Include <debugs> | |
; Auto Execute | |
OnMessage(0x201, "Message_Handler") ; 513 WM_LBUTTONDOWN | |
OnMessage(0x204, "Message_Handler") ; 516 WM_RBUTTONDOWN | |
OnMessage(0x205, "Message_Handler") ; 517 WM_RBUTTONUP | |
OnMessage(0x100, "Message_Handler") ; 256 WM_KEYDOWN | |
OnMessage(0x111, "Message_Handler") ; 273 WM_COMMAND | |
; Variables | |
global hks := {} | |
global hk_times := {} | |
global var_check := "``-=[]\;',./1234567890" | |
global var_replacers := {"``":"bt", "-":"mi", "=":"eq", "[":"ob", "]":"cb", "\":"bs" | |
, ";":"sc", "'":"sq", ",":"cm", ".":"pd", "/":"fs", "1":"on", "2":"tw" | |
, "3":"th", "4":"fr", "5":"fv", "6":"sx", "7":"sv", "8":"et", "9":"ni" | |
, "0":"zr"} | |
; GUI | |
Gui, Add, Text, x20 y20 w81 h23 Right,Enter key/button | |
Gui, Add, Edit, x110 y20 w47 h21 ReadOnly Center hwnded_hwnd_hotkey ved_hotkey | |
Gui, Add, Text, x20 y50 w81 h23 Right,Sensitivity (ms) | |
Gui, Add, Edit, x110 y50 w47 h21 Center Number ved_sens,180 | |
Gui, Add, Button, x180 y18 w120 h54 -Default gAdd_KeyButton,Add | |
Gui, Add, ListView, x20 y80 w280 h193,Key/Button|Sensitivity|On/Off | |
Gui, Show, w320 h291 | |
Menu, Tray, NoStandard | |
Menu, Tray, Add, Show | |
Menu, Tray, Default, Show | |
Menu, Tray, Add, Exit | |
DllCall("User32\HideCaret",uptr,ed_hwnd_hotkey) | |
Return | |
GuiSize: | |
if (a_eventInfo == 1) | |
Gui, Hide | |
return | |
Show: | |
Gui, Show | |
return | |
Exit: | |
GuiClose: | |
ExitApp | |
; Labels | |
Add_KeyButton: | |
Gui, Submit, NoHide | |
GuiControlGet, keyButton,, ed_hotkey | |
while (a_index <= LV_GetCount()) | |
{ | |
LV_GetText(row_text, a_index) | |
if (keyButton == row_text) | |
duplicate := 1 | |
} | |
if (duplicate) | |
MsgBox, Duplicate Found | |
else | |
{ | |
LV_Add("", keyButton,ed_sens, "On") | |
; Hk_Set_Hk_Array(keyButton, "Untitled - Notepad", ed_sens) | |
Hk_Set_Hk_Array(keyButton, "7 Days To Die", ed_sens) | |
Hk_Set_Timer_Array(keyButton) | |
} | |
duplicate := 0 | |
return | |
; Functions | |
Hk_Hold(){ | |
btn := Hk_Trim_Mods(a_thisHotkey) | |
if (Hk_Timer(a_thisHotkey)) | |
{ | |
SendInput, {%btn% Down} | |
; t(btn,"Good") | |
} | |
else | |
{ | |
SendInput, {%btn% Up} | |
; t(btn,"Bad") | |
} | |
} | |
Hk_Set_Hk_Array(hk_sym, window, sens = 180){ | |
hk_name := Hk_Get_Valid_Name(hk_sym) | |
hks[hk_name] := {window:window, sens:sens, mods:"~$" hk_sym " UP", norm:hk_sym} | |
Hotkey, ifWinActive, % hks[hk_name].window | |
Hotkey, % hks[hk_name].mods, Hk_Hold | |
} | |
Hk_Set_Timer_Array(hk){ | |
hk := Hk_Get_Valid_Name(hk) | |
hk_times[hk] := {press_cnt:0, press1:0, press2:0} | |
} | |
Hk_Timer(hk){ | |
is_double := 0 | |
hk := Hk_Trim_Mods(hk) | |
hk := Hk_Get_Valid_Name(hk) | |
hk_times[hk].press_cnt++ | |
if (hk_times[hk].press_cnt == 1) | |
hk_times[hk].press1 := a_tickCount | |
else if (hk_times[hk].press_cnt == 2) | |
{ | |
hk_times[hk].press2 := a_tickCount | |
if (hk_times[hk].press2 - hk_times[hk].press1 < hks[hk].sens) | |
is_double := 1 | |
else | |
is_double := 0 | |
hk_times[hk].press_cnt := 1 | |
hk_times[hk].press1 := a_tickCount | |
} | |
return is_double | |
} | |
Hk_Get_Valid_Name(hk){ | |
if (InStr(var_check, hk)) | |
for k,v in var_replacers | |
if (k == hk) | |
hk := v | |
return hk | |
} | |
Hk_Trim_Mods(hk){ | |
RegExMatch(hk, "~\$(\S+)\s", m) | |
return m1 | |
} | |
Message_Handler(wParam, lParam, msg){ | |
; DllCall("User32\HideCaret",uptr,ed_hwnd_hotkey) | |
if (msg == 273) | |
{ | |
; WM_COMMAND help by user: just me (http://ahkscript.org/boards/viewtopic.php?p=49593#p49593) | |
NotificationCode := (wParam >> 16) & 0xFFFF | |
if (NotificationCode = 0x0100) ; EN_SETFOCUS | |
{ | |
GuiControlGet, FocusedControl, FocusV | |
if (FocusedControl = "ed_hotkey") | |
DllCall("HideCaret", "Ptr", lParam) | |
} | |
} | |
if (msg == 513 && A_GuiControl == "ed_hotkey") | |
GuiControl,, ed_hotkey, LButton | |
else if (msg == 516 && A_GuiControl == "ed_hotkey") | |
GuiControl,, ed_hotkey, RButton | |
else if (msg == 517 && a_guiControl == "ed_hotkey") | |
return 0 | |
else if (msg == 256 && a_guiControl == "ed_hotkey") | |
GuiControl,, ed_hotkey, % GetKeyName(Format("VK{:x}", wParam)) | |
; GuiControl,, ed_hotkey, % GetKeyName("VK" Format( "{:x}", wParam ) ) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment