Advertisement
djvj

Untitled

Aug 2nd, 2015
373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.30 KB | None | 0 0
  1. MCRC=C7E6E7CF
  2. MVersion=1.0.3
  3.  
  4. ; xHotkey Functions:
  5. ; xHotkey - Extended Hotkey command allowing the use of multile keys pressed at the same time to execute specific labels for single click, hold Key, double click and more them two clicks modes.
  6. ; example of use: singleclick: XHotkey("~Esc","CloseProcess")
  7. ; hold 2 seconds: XHotkey("~Esc",,,"PauseLabel",2)
  8. ; two simultaneous functions: XHotkey("~Esc","CloseProcess",,"PauseLabel",2)
  9. ; Single, Hold, Double or three or more clicks asigned to different gosub labels: XHotkey("~A|~S&~D|~q&~w&~e|~Joy1 & ~Joy2","SingleClick",,"ClickandHold",1,"DoubleClick","MoreThanTwoClicks",600)
  10. ; disable xHotkey: XHotkey("~Esc",,"OFF")
  11. ;
  12. ; xHotKeywrapper - xHotkey command Wrapper for RocketLauncher use (allows sinlge line definition of XHotkey parameters)
  13. ; example of use: XHotKeywrapper("~Esc|H2000:~Z|~X|~A|~S&~D|~q & ~w & ~e|~Joy1 & ~Joy2|D:T:~F|D:T:~R&~T","CloseProcess")
  14. ;
  15. ; ForceHoldKey - function to force hold press mode for any Hotkey
  16. ; example of use: forceHoldKey("A|~q &~W&~e")
  17. ;
  18. ; xHotkeyVarEdit - function to remove or add key modifiers to previous defined XHotkeyWrapper key variables (these modifiers update should be called before calling the XHotkeyWrapper function)
  19. ; example of use: exitEmulatorKey=Esc
  20. ; xHotkeyVarEdit(exitEmulatorKey,"exitEmulatorKey","~","Add")
  21. ; xHotKeywrapper(exitEmulatorKey,"CloseProcess")
  22.  
  23. ; ---------------------------------------------
  24. ; XHOTKEY FUNCTION CODE WRAPPER
  25. ; ---------------------------------------------
  26. ; H1000 - means to enable hold for 1 second of the key group to go to label
  27. ; S or nothing - means to enable single click of the key group to go to label
  28. ; D - means to enable double click of the key group to go to label (If you use a number after the D, D600:, it means that xhotkey will wait 600 miliseconds for a second key press)
  29. ; T - means to enable more than two clicks of the key group to go to label
  30.  
  31. XHotKeywrapper(ExtendedKeyName,GeneralLabel,Options="ON"){
  32. If !ExtendedKeyName
  33. Return
  34. Loop, parse, ExtendedKeyName, |, %A_Space%
  35. {
  36. Nooption := true
  37. Keyoptions := DelimitedReversal(A_LoopField,"`:")
  38. Loop, parse, Keyoptions, `:, %A_Space%
  39. {
  40. wrapperLabelForSingleKey :=
  41. wrapperLabelForHoldKey :=
  42. wrapperLabelForDoubleClick :=
  43. wrapperLabelForMoreThanTwoClicks :=
  44. wrapperKeyHoldWait :=
  45. wrapperDoubleClickWait :=
  46. currentparseitem := A_index
  47. If currentparseitem = 1
  48. Keys := A_loopfield
  49. Else {
  50. If A_loopfield contains S,H,D,T
  51. Nooption := false
  52. If InStr(A_loopfield,"S")
  53. wrapperLabelForSingleKey := GeneralLabel
  54. If InStr(A_loopfield,"H"){
  55. wrapperLabelForHoldKey := GeneralLabel
  56. StringTrimLeft, wrapperKeyHoldWait, A_Loopfield, 1
  57. wrapperKeyHoldWait := wrapperKeyHoldWait/1000
  58. If not wrapperKeyHoldWait
  59. wrapperKeyHoldWait := 1 ;default value
  60. }
  61. If InStr(A_loopfield,"D"){
  62. wrapperLabelForDoubleClick := GeneralLabel
  63. StringTrimLeft, wrapperDoubleClickWait, A_Loopfield, 1
  64. If not wrapperDoubleClickWait
  65. wrapperDoubleClickWait := 600 ;default value
  66. }
  67. If InStr(A_loopfield,"T"){
  68. wrapperLabelForMoreThanTwoClicks := GeneralLabel
  69. StringTrimLeft, wrapperDoubleClickWait, A_Loopfield, 1
  70. If not wrapperDoubleClickWait
  71. wrapperDoubleClickWait := 600 ;default value
  72. }
  73. }
  74. }
  75. If Nooption
  76. wrapperLabelForSingleKey := GeneralLabel
  77. If Keyoptions
  78. XHotkey(Keys,wrapperLabelForSingleKey,Options,wrapperLabelForHoldKey,wrapperKeyHoldWait,wrapperLabelForDoubleClick,wrapperLabelForMoreThanTwoClicks,wrapperDoubleClickWait)
  79. }
  80. Return
  81. }
  82.  
  83. DelimitedReversal( str, delimiter="`n" ) { ; By [VxE]. Reverses the order of substrings in 'string'.
  84. oel := ErrorLevel, ptr := A_PtrSize = "" ? "UInt" : "Ptr", len := StrLen( str ) << uni := A_IsUnicode = 1
  85. Loop, Parse, str, % delimiter := SubStr( delimiter "`n", 1, 1 )
  86. If ( siz := StrLen( sub := A_LoopField . ( A_Index = 1 ? "" : delimiter ) ) << uni )
  87. DllCall( "RtlMoveMemory", ptr, &str + len -= siz, ptr, &sub, "UInt", siz )
  88. Return str, ErrorLevel := oel
  89. }
  90.  
  91. ; ---------------------------------------------
  92. ; XHOTKEY FUNCTION CODE
  93. ; ---------------------------------------------
  94. ;Options:
  95. ; ExtendedKeyName: ~A&~S|~q & ~w & ~e|~Joy1 & ~Joy2
  96. ; LabelForSingleKey: Same as original Hotkey command Label.
  97. ; Options: Original Hotkey command options (UseErrorLevel,On,Off,B or B0,Pn,Tn)
  98. ; KeyWait: Optional, Time needed holding down the key combination for going to the label defined on LabelForSingleKey. If empty, the key combination redirects to the label instantaneously with a single key press.
  99. ; LabelForDoubleClick: The label name whose contents will be executed when the double click is executed.
  100. ; LabelForMoreThanTwoClicks: The label name whose contents will be executed when more them two clicks are executed.
  101. ; DoubleClickKeyWait: Optional, Time between key press to register a double click (go to the label defined on LabelForDoubleKey). If empty there is no double click label redirection (acts always as a single key press).
  102.  
  103. ;Preprocess multiple key assignments
  104. XHotkey(ExtendedKeyName,LabelForSingleKey="",Options="ON",LabelForHoldKey="",KeyHoldWait="1",LabelForDoubleClick="",LabelForMoreThanTwoClicks="",DoubleClickKeyWait="600"){
  105. Global
  106. IgnoreMultipleKeys := 0
  107. Loop, parse, ExtendedKeyName, |, %A_Space%
  108. {
  109. XHotkeyTableCreation(A_LoopField,LabelForSingleKey,Options,LabelForHoldKey,KeyHoldWait,LabelForDoubleClick,LabelForMoreThanTwoClicks,DoubleClickKeyWait)
  110. }
  111. Return
  112. }
  113.  
  114. ;xHotkey Table Creation
  115. XHotkeyTableCreation(KeyGroup,LabelForSingleKey="",Options="",LabelForHoldKey="",KeyHoldWait="",LabelForDoubleClick="",LabelForMoreThanTwoClicks="",DoubleClickKeyWait=""){
  116. Global
  117. GoSubTimeDelay := 30 ; minimun time in miliseconds between key commands (necessary to avoid multiple gosub calls)
  118. LabelHoldCallDelay := 3000 ; minimun time in miliseconds between labels call after a hold call (necessary to avoid ghost label calls after an hold key press)
  119. KeyGroup := RegexReplace( KeyGroup, "^\s+|\s+$") ; KeyGroup without any spaces
  120. ;Saving sorted Keys to avoid considering different ordered keys as different table items (ex. A&S and S&A should be the same table item)
  121. Keys := Array_Lib()
  122. Loop, Parse, KeyGroup, &,%a_space%
  123. {
  124. Keys.append(A_LoopField)
  125. }
  126. KeyGroup := Keys.sort().join("&")
  127. KeyGroupWithSpaces := KeyGroup
  128. If InStr(KeyGroup,"&")
  129. StringReplace, KeyGroupWithSpaces, KeyGroup, &, %a_space%&%a_space% ; KeyGroup with spaces between multiple keys to avoid autohotkey error in normal hotkey call
  130. If !XHotKeyTable
  131. XHotKeyTable:=[] ; create key table XHotKeyTable[TableNumber,keynumber,column]
  132. If KeyGroup not in %TableKeyGroups%
  133. {
  134. KeyGroupNumber++
  135. currentGroup := KeyGroupNumber
  136. currentkeyNumber := 0
  137. XHotKeyTable[currentGroup,1,1] := KeyGroup
  138. Loop, Parse, KeyGroup, &,%a_space%
  139. {
  140. currentkeyNumber++
  141. currentkey := RegexReplace( A_LoopField, "^\s+|\s+$" )
  142. XHotKeyTable[currentGroup,currentkeyNumber,2] := currentkey ; Store each exit key in column 3 as they are defined in the var
  143. XHotKeyTable[currentGroup,1,3] := currentkeyNumber ; number of keys in this group
  144. replace := {"~":"","*":"","$":""} ; Saving Keys without modifiers
  145. currentKeyClean := currentkey
  146. For what, with in replace
  147. {
  148. If InStr(currentKeyClean,what)
  149. StringReplace, currentKeyClean, currentKeyClean, %what%, %with%, All
  150. }
  151. XHotKeyTable[currentGroup,currentkeyNumber,4] := currentKeyClean
  152. }
  153. XHotKeyTable[currentGroup,1,5] := 0 ; initialize key press count for single, double and triple clicks
  154. XHotKeyTable[currentGroup,1,6] := LabelForSingleKey ; save label for single click
  155. XHotKeyTable[currentGroup,1,7] := LabelForHoldKey ; save label for press and hold
  156. XHotKeyTable[currentGroup,1,8] := KeyHoldWait ; save key hold wait time
  157. XHotKeyTable[currentGroup,1,9] := LabelForDoubleClick ; save label for double click
  158. XHotKeyTable[currentGroup,1,10] := LabelForMoreThanTwoClicks ; save label for three or more clicks
  159. XHotKeyTable[currentGroup,1,11] := DoubleClickKeyWait ; save label for double click time between keys
  160. If not InStr(options, "OFF"){
  161. If LabelForSingleKey
  162. XHotKeyTable[currentGroup,1,13] := true
  163. If LabelForHoldKey
  164. XHotKeyTable[currentGroup,2,13] := true
  165. If LabelForDoubleClick
  166. XHotKeyTable[currentGroup,3,13] := true
  167. If LabelForMoreThanTwoClicks
  168. XHotKeyTable[currentGroup,4,13] := true
  169. } Else {
  170. If LabelForSingleKey
  171. XHotKeyTable[currentGroup,1,13] := false
  172. If LabelForHoldKey
  173. XHotKeyTable[currentGroup,2,13] := false
  174. If LabelForDoubleClick
  175. XHotKeyTable[currentGroup,3,13] := false
  176. If LabelForMoreThanTwoClicks
  177. XHotKeyTable[currentGroup,4,13] := false
  178. }
  179. If (((Instr(KeyGroup,"joy")) and (XHotKeyTable[currentGroup,1,3]=1)) or ( not(Instr(KeyGroup,"joy")) and (XHotKeyTable[currentGroup,1,3]<=2))) and (((LabelForHoldKey="") and (LabelForDoubleClick="") and (LabelForMoreThanTwoClicks="") )){ ; defining normal hotkey command If the key group has: only one joy button or If it is a single key press with one or two simultaneous keys
  180. Log("XHotkeyTableCreation - " . (If options = "OFF" ? "Disabling """ . LabelForSingleKey . """ standard Hotkey method for key(s): """ . KeyGroupWithSpaces . """" : "Using standard Hotkey method for key(s): """ . KeyGroupWithSpaces . """ to call label: """ . LabelForSingleKey . """"),5)
  181. Hotkey, % KeyGroupWithSpaces, %LabelForSingleKey%, %Options% ; normal hotkey command
  182. } Else { ; defining extended hotkey command If there are more them two simultaneous keys pressed (more them one for joy), or If it has hold, double or more click presses
  183. Log("XHotkeyTableCreation - " . (If options = "OFF" ? "Disabling extended Hotkey method for key(s): """ . KeyGroup . """" : "Using extended Hotkey method for key(s): """ . KeyGroup . """ to call a group label"),5)
  184. Loop, Parse, KeyGroup, &,%a_space%
  185. {
  186. Hotkey, % XHotKeyTable[currentGroup,A_Index,2], HotKeyModeProcess, %Options% ; go to sub to test multiple key press If any exit emulator key is pressed
  187. XHotKeyTable[currentGroup,1,12] := true
  188. }
  189. }
  190. TableKeyGroups .= KeyGroup . ","
  191. Return XHotKeyTable
  192. } Else {
  193. currentGroup:=0
  194. Loop, %KeyGroupNumber%
  195. {
  196. currentGroup++
  197. currentKeysonKeyGroup := XHotKeyTable[currentGroup,1,1]
  198. If (currentKeysonKeyGroup = KeyGroup){
  199. Break
  200. }
  201. }
  202. If not InStr(options, "OFF"){
  203. If LabelForSingleKey
  204. XHotKeyTable[currentGroup,1,13] := true
  205. If LabelForHoldKey
  206. XHotKeyTable[currentGroup,2,13] := true
  207. If LabelForDoubleClick
  208. XHotKeyTable[currentGroup,3,13] := true
  209. If LabelForMoreThanTwoClicks
  210. XHotKeyTable[currentGroup,4,13] := true
  211. } Else {
  212. If LabelForSingleKey
  213. XHotKeyTable[currentGroup,1,13] := false
  214. If LabelForHoldKey
  215. XHotKeyTable[currentGroup,2,13] := false
  216. If LabelForDoubleClick
  217. XHotKeyTable[currentGroup,3,13] := false
  218. If LabelForMoreThanTwoClicks
  219. XHotKeyTable[currentGroup,4,13] := false
  220. }
  221. If not InStr(options, "OFF"){
  222. If LabelForSingleKey
  223. If (XHotKeyTable[currentGroup,1,6] <> LabelForSingleKey)
  224. XHotKeyTable[currentGroup,1,6] := LabelForSingleKey ; update label for single click
  225. If LabelForHoldKey
  226. If XHotKeyTable[currentGroup,1,7] <> LabelForHoldKey
  227. XHotKeyTable[currentGroup,1,7] := LabelForHoldKey ; update label for press and hold
  228. If KeyHoldWait
  229. If XHotKeyTable[currentGroup,1,8] <> KeyHoldWait
  230. XHotKeyTable[currentGroup,1,8] := KeyHoldWait ; update key hold wait time
  231. If LabelForDoubleClick
  232. If XHotKeyTable[currentGroup,1,9] <> LabelForDoubleClick
  233. XHotKeyTable[currentGroup,1,9] := LabelForDoubleClick ; update label for double click
  234. If LabelForMoreThanTwoClicks
  235. If XHotKeyTable[currentGroup,1,10] <> LabelForMoreThanTwoClicks
  236. XHotKeyTable[currentGroup,1,10] := LabelForMoreThanTwoClicks ; update label for three or more clicks
  237. If DoubleClickKeyWait
  238. If XHotKeyTable[currentGroup,1,11] <> DoubleClickKeyWait
  239. XHotKeyTable[currentGroup,1,11] := DoubleClickKeyWait ; update label for double click time between keys
  240. }
  241. If not XHotKeyTable[currentGroup,1,12] ; disabling previous normal hotkey command If previously defined
  242. { Hotkey, %KeyGroupWithSpaces%, Off
  243. Log("XHotkeyTableCreation - Disabled Hotkey for: """ . KeyGroupWithSpaces . """",5)
  244. }
  245. If (((Instr(KeyGroup,"joy")) and (XHotKeyTable[currentGroup,1,3]=1)) or ( not(Instr(KeyGroup,"joy")) and (XHotKeyTable[currentGroup,1,3]<=2))) and (((LabelForHoldKey="") and (LabelForDoubleClick="") and (LabelForMoreThanTwoClicks="") )){ ; defining normal hotkey command If the key group has: only one joy button or If it is a single key press with one or two simultaneous keys
  246. Log("XHotkeyTableCreation - " . (If options = "OFF" ? "Disabling """ . LabelForSingleKey . """ standard Hotkey method for key(s): """ . KeyGroupWithSpaces . """" : "Using standard Hotkey method for key(s): """ . KeyGroupWithSpaces . """ to call label: """ . LabelForSingleKey . """"),5)
  247. Hotkey, % KeyGroupWithSpaces, %LabelForSingleKey%, %Options% ; normal hotkey command
  248. } Else { ; defining extended hotkey command If there are more them two simultaneous keys pressed (more them one for joy), or If it has hold, double or more click presses
  249. Log("XHotkeyTableCreation - " . (If options = "OFF" ? "Disabling extended Hotkey method for key(s): """ . KeyGroup . """" : "Using extended Hotkey method for key(s): """ . KeyGroup . """ to call a group label"),5)
  250. Loop, Parse, KeyGroup, &,%a_space%
  251. {
  252. Hotkey, % XHotKeyTable[currentGroup,A_Index,2], HotKeyModeProcess, %Options% ; go to sub to test multiple key press If any exit emulator key is pressed
  253. XHotKeyTable[currentGroup,1,12] := true
  254. }
  255. }
  256. If not InStr(options, "OFF")
  257. If ForceHoldKeysList
  258. forceHoldKey(ForceHoldKeysList)
  259. Return
  260. }
  261. }
  262.  
  263. HotKeyModeProcess:
  264. If (A_TickCount < LastHotKeyModeProcessTime+GoSubTimeDelay) ; XHotkeyMinimunDelay necessary to avoid multiple calls to subs in multiple Key groups
  265. Return
  266. LastHotKeyModeProcessTime := A_TickCount
  267. currentkey := A_ThisHotkey ; current pressed keys
  268. replace := {"~":"","*":"","$":""} ; Saving current Key without modifiers to use on Keywait
  269. For what, with in replace
  270. {
  271. If InStr(currentkey,what)
  272. StringReplace, currentkey, currentkey, %what%, %with%, All
  273. }
  274. currentGroup:=0
  275. Loop, %KeyGroupNumber%
  276. {
  277. currentGroup++
  278. If XHotKeyTable[currentGroup,1,12]
  279. {
  280. If AllKeysPressed(currentGroup) {
  281. CurrentPressandHoldLabel := % XHotKeyTable[currentGroup,1,7]
  282. CurrentKeyHoldWait := % XHotKeyTable[currentGroup,1,8]
  283. If %CurrentPressandHoldLabel%
  284. KeyWait, %currentKey%, t%currentKeyHoldWait%
  285. Else
  286. KeyWait, %currentKey%
  287. If (GetKeyState(currentKey,"p")) ; could be a hold key press
  288. {
  289. If IsLabel(CurrentPressandHoldLabel)
  290. If XHotKeyTable[currentGroup,2,13]
  291. If (A_TickCount > lastHoldLabelCall + LabelHoldCallDelay)
  292. {
  293. lastHoldLabelCall := A_TickCount
  294. Log("1",3)
  295. Gosub, %CurrentPressandHoldLabel%
  296. }
  297. LastGoSubTime := A_TickCount
  298. currentHoldKeyPressed := currentKey
  299. SetTimer, checkHoldKeyUp, 50
  300. XHotKeyTable[currentGroup,1,5] := 0 ; reset the count to prepare for the next series of presses
  301. Return
  302. } Else {
  303. If (XHotKeyTable[currentGroup,1,5]) > 0 { ; SetTimer already started, so we log the keypress instead
  304. If (IgnoreMultipleKeys>0) { ; necessary to avoid multiple key count in multiple Key groups
  305. IgnoreMultipleKeys--
  306. Return
  307. }
  308. IgnoreMultipleKeys := XHotKeyTable[currentGroup,1,3]-1
  309. XHotKeyTable[currentGroup,1,5]++
  310. Return
  311. }
  312. XHotKeyTable[currentGroup,1,5] := 1 ; Otherwise, this is the first press of a new series. Set count to 1 and start the timer:
  313. ActiveCurrentGroup := currentGroup
  314. CurrentDoubleClickKeyWait := % XHotKeyTable[ActiveCurrentGroup,1,11]
  315. If XHotKeyTable[ActiveCurrentGroup,1,9] or XHotKeyTable[ActiveCurrentGroup,1,10] {
  316. If XHotKeyTable[currentGroup,3,13] or XHotKeyTable[currentGroup,4,13]
  317. SetTimer, MultipleClickCheck, %CurrentDoubleClickKeyWait% ; Wait for more presses within a CurrentDoubleClickKeyWait millisecond time.
  318. Return
  319. } Else {
  320. CurrentSinglePressLabel := % XHotKeyTable[ActiveCurrentGroup,1,6]
  321. If IsLabel(CurrentSinglePressLabel)
  322. {
  323. If XHotKeyTable[currentGroup,1,13]
  324. If (A_TickCount > lastHoldLabelCall + LabelHoldCallDelay)
  325. { Log("2",3)
  326.  
  327. Gosub %CurrentSinglePressLabel%
  328. }
  329. LastGoSubTime := A_TickCount
  330. }
  331. XHotKeyTable[ActiveCurrentGroup,1,5] := 0 ; reset the count to prepare for the next series of presses
  332. }
  333. Return
  334. }
  335. }
  336. }
  337. }
  338. Return
  339.  
  340. checkHoldKeyUp:
  341. If !(GetKeyState(currentHoldKeyPressed,"p"))
  342. SetTimer, checkHoldKeyUp, off
  343. Return
  344.  
  345. MultipleClickCheck: ;checking If the key group was pressed once, twice or more times.
  346. SetTimer, MultipleClickCheck, off
  347. CurrentSinglePressLabel := % XHotKeyTable[ActiveCurrentGroup,1,6]
  348. CurrentDoubleClickLabel := % XHotKeyTable[ActiveCurrentGroup,1,9]
  349. CurrentLabelForMoreThanTwoClicks := % XHotKeyTable[ActiveCurrentGroup,1,10]
  350. If (XHotKeyTable[ActiveCurrentGroup,1,5] > 2) and (IsLabel(CurrentLabelForMoreThanTwoClicks)) { ; The key was pressed three or more times.
  351. If XHotKeyTable[currentGroup,4,13]
  352. If (A_TickCount > lastHoldLabelCall + LabelHoldCallDelay) {
  353. Log("3",3)
  354.  
  355. Gosub, %CurrentLabelForMoreThanTwoClicks%
  356. }
  357. LastGoSubTime := A_TickCount
  358. } Else If (XHotKeyTable[ActiveCurrentGroup,1,5] > 1) and (IsLabel(CurrentDoubleClickLabel)) { ; The key was pressed twice.
  359. If XHotKeyTable[currentGroup,3,13]
  360. If (A_TickCount > lastHoldLabelCall + LabelHoldCallDelay) {
  361. Log("4",3)
  362. Gosub, %CurrentDoubleClickLabel%
  363. }
  364. LastGoSubTime := A_TickCount
  365. } Else {
  366. If IsLabel(CurrentSinglePressLabel)
  367. If XHotKeyTable[currentGroup,1,13]
  368. If (A_TickCount > lastHoldLabelCall + LabelHoldCallDelay) {
  369. Log("5",3)
  370. Gosub %CurrentSinglePressLabel%
  371. }
  372. LastGoSubTime := A_TickCount
  373. }
  374. XHotKeyTable[ActiveCurrentGroup,1,5] := 0 ; reset the count to prepare for the next series of presses
  375. Return
  376.  
  377.  
  378. AllKeysPressed(currentKeygroup) { ; function to check If the keys are pressed simultneously
  379. Global
  380. ExitKeysPressed := true
  381. Loop, % XHotKeyTable[currentKeygroup,1,3]
  382. {
  383. If XHotKeyTable[currentKeygroup,A_index,4]
  384. If not (GetKeyState(XHotKeyTable[currentKeygroup,A_index,4],"p"))
  385. ExitKeysPressed := false
  386. }
  387. If ExitKeysPressed
  388. Return 1
  389. Return 0
  390. }
  391.  
  392.  
  393. ; ---------------------------------------------
  394. ; FORCEHOLDKEY FUNCTION CODE
  395. ; ---------------------------------------------
  396. ForceHoldKey(FullKeyHoldList,KeyHoldWait="1") { ; function to force hold press mode for any Hotkey
  397. Global
  398. ForceHoldKeysList .= FullKeyHoldList . "|"
  399. StringTrimRight,TableKeysAux,TableKeyGroups,1
  400. Loop, parse, TableKeysAux, `,, %A_Space%
  401. {
  402. KeysArray%A_Index% := A_Loopfield
  403. }
  404. replace := {"~":"","*":"","$":""} ; removing modifiers before comparing keys
  405. For what, with in replace
  406. {
  407. If InStr(TableKeysAux,what)
  408. StringReplace, TableKeysAux, TableKeysAux, %what%, %with%, All
  409. }
  410. Loop, parse, FullKeyHoldList, |, %A_Space%
  411. {
  412. KeyHoldListGroup := A_LoopField
  413. KeyHoldListGroup := RegexReplace( KeyHoldListGroup, "i)S:" ) ; removing options from keys
  414. KeyHoldListGroup := RegexReplace( KeyHoldListGroup, "i)H(.*):" ) ; removing options from keys
  415. KeyHoldListGroup := RegexReplace( KeyHoldListGroup, "i)D(.*):" ) ; removing options from keys
  416. KeyHoldListGroup := RegexReplace( KeyHoldListGroup, "i)T(.*):" ) ; removing options from keys
  417. KeyHoldListGroup := RegexReplace( KeyHoldListGroup, "^\s+|\s+$") ; KeyGroup without any spaces
  418. ;Saving sorted Keys to avoid considering different ordered keys as different table items (ex. A&S and S&A should be the same table item)
  419. Keys := Array_Lib()
  420. Loop, Parse, KeyHoldListGroup, &,%a_space%
  421. {
  422. Keys.append(A_LoopField)
  423. }
  424. KeyHoldListGroup := Keys.sort().join("&")
  425. replace := {"~":"","*":"","$":""} ; removing modifiers before comparing keys
  426. For what, with in replace
  427. {
  428. If InStr(KeyHoldListGroup,what)
  429. StringReplace, KeyHoldListGroup, KeyHoldListGroup, %what%, %with%, All
  430. }
  431. Loop, Parse, TableKeysAux, `,,%a_space%
  432. {
  433. If (KeyHoldListGroup = A_LoopField){ ; Key to force hold mode is in the keys defined by the user
  434. currentComboKey := % KeysArray%A_Index%
  435. If InStr(currentComboKey,"&")
  436. StringReplace, currentComboKey, currentComboKey, &, %a_space%&%a_space% ; KeyGroup with spaces between multiple keys to avoid autohotkey error in normal hotkey call
  437. If not XHotKeyTable[A_index,1,12] ; disabling normal hotkey command If previously defined
  438. Hotkey, %currentComboKey%, Off
  439. Loop, Parse, currentComboKey, &,%a_space%
  440. {
  441. Hotkey, %A_LoopField%, HotKeyModeProcess, On
  442. }
  443. XHotKeyTable[A_index,1,12] := true ; enabling XHotKey mode in table
  444. XHotKeyTable[A_index,1,13] := "" ; disabling single press key
  445. XHotKeyTable[A_index,2,13] := true ; enabling press and hold key
  446. XHotKeyTable[A_index,3,13] := "" ; disabling double press key
  447. XHotKeyTable[A_index,4,13] := "" ; disabling three or more presses key
  448. If XHotKeyTable[A_index,1,6] ; assigning single press label to press and hold If existent
  449. XHotKeyTable[A_index,1,7] := XHotKeyTable[A_index,1,6]
  450. Else If XHotKeyTable[A_index,1,9] ; Else assigning double press label to press and hold If existent
  451. XHotKeyTable[A_index,1,7] := XHotKeyTable[A_index,1,9]
  452. Else If XHotKeyTable[A_index,1,10] ; Else assigning three or more presses label to press and hold If existent
  453. XHotKeyTable[A_index,1,7] := XHotKeyTable[A_index,1,10]
  454. XHotKeyTable[A_index,1,6] := "" ; erasing single press label
  455. If not XHotKeyTable[A_index,1,8] ; determining hold wait time If not previously defined
  456. XHotKeyTable[A_index,1,8] := KeyHoldWait
  457. XHotKeyTable[A_index,1,9] := "" ; erasing double press label
  458. XHotKeyTable[A_index,1,10] := "" ; erasing three or more presses label
  459. XHotKeyTable[A_index,1,9] := "" ; erasing double press wait
  460. }
  461. }
  462.  
  463. }
  464. Return
  465. }
  466.  
  467.  
  468. ; ---------------------------------------------
  469. ; XHOTKEYVAREDIT FUNCTION
  470. ; ---------------------------------------------
  471. xHotKeyVarEdit(KeyEditList,KeyEditListVar,Keymodifier="",action="") {
  472. Loop, parse, %KeyEditListVar%, |, %A_Space%
  473. {
  474. initialKeyEditListGroup := A_LoopField
  475. replace := {"~":"","*":"","$":""} ; removing modifiers before comparing keys
  476. currentVarKeyGroup := A_LoopField
  477. For what, with in replace
  478. {
  479. If InStr(currentVarKeyGroup,what)
  480. StringReplace, currentVarKeyGroup, currentVarKeyGroup, %what%, %with%, All
  481. }
  482. currentVarKeyGroup := RegexReplace( currentVarKeyGroup, "i)S:" ) ; removing options from keys
  483. currentVarKeyGroup := RegexReplace( currentVarKeyGroup, "i)H(.*):" ) ; removing options from keys
  484. currentVarKeyGroup := RegexReplace( currentVarKeyGroup, "i)D(.*):" ) ; removing options from keys
  485. currentVarKeyGroup := RegexReplace( currentVarKeyGroup, "i)T(.*):" ) ; removing options from keys
  486. currentVarKeyGroup := RegexReplace( currentVarKeyGroup, "^\s+|\s+$") ; KeyGroup without any spaces
  487. Keys := Array_Lib()
  488. Loop, Parse, currentVarKeyGroup, &,%a_space%
  489. {
  490. Keys.append(A_LoopField)
  491. }
  492. currentVarKeyGroup := Keys.sort().join("&")
  493. groupChecked := false
  494. Loop, parse, KeyEditList, |, %A_Space%
  495. {
  496. currentKeyEditListGroup := A_LoopField
  497. replace := {"~":"","*":"","$":""} ; removing modifiers before comparing keys
  498. KeyEditListGroup := A_LoopField
  499. For what, with in replace
  500. {
  501. If InStr(KeyEditListGroup,what)
  502. StringReplace, KeyEditListGroup, KeyEditListGroup, %what%, %with%, All
  503. }
  504. KeyEditListGroup := RegexReplace( KeyEditListGroup, "i)S:" ) ; removing options from keys
  505. KeyEditListGroup := RegexReplace( KeyEditListGroup, "i)H(.*):" ) ; removing options from keys
  506. KeyEditListGroup := RegexReplace( KeyEditListGroup, "i)D(.*):" ) ; removing options from keys
  507. KeyEditListGroup := RegexReplace( KeyEditListGroup, "i)T(.*):" ) ; removing options from keys
  508. KeyEditListGroup := RegexReplace( KeyEditListGroup, "^\s+|\s+$") ; KeyGroup without any spaces
  509. Keys := Array_Lib()
  510. Loop, Parse, KeyEditListGroup, &,%a_space%
  511. {
  512. Keys.append(A_LoopField)
  513. }
  514. KeyEditListGroup := Keys.sort().join("&")
  515. If (KeyEditListGroup = currentVarKeyGroup){
  516. currentEditKey :=
  517. Loop, Parse, initialKeyEditListGroup, &,%a_space%
  518. {
  519. currentEditKey := A_LoopField
  520. If(action="Remove"){
  521. If InStr(currentEditKey,Keymodifier)
  522. StringReplace, currentEditKey, currentEditKey, %Keymodifier%, , all
  523. }
  524. If(action="Add"){
  525. ReverseKeyEdit := DelimitedReversal(currentEditKey,"`:")
  526. Loop, parse, ReverseKeyEdit, `:, %A_Space%
  527. {
  528. currentfield := A_LoopField
  529. If (a_index = 1) {
  530. If not InStr(currentfield,Keymodifier)
  531. currentEditKey := Keymodifier . currentfield
  532. Else
  533. currentEditKey := currentfield
  534. } Else {
  535. currentEditKey := currentfield . ":" . currentEditKey
  536. }
  537. }
  538. }
  539. currentKeyEditListVar := currentKeyEditListVar . "&" . currentEditKey
  540. groupChecked := true
  541. }
  542. }
  543. }
  544. If not groupChecked
  545. currentKeyEditListVar := "&" . initialKeyEditListGroup
  546. StringTrimLeft,currentKeyEditListVar,currentKeyEditListVar,1
  547. FinalKeyEditListVar := FinalKeyEditListVar . "|" . currentKeyEditListVar
  548. currentKeyEditListVar := ""
  549. }
  550. StringTrimLeft,FinalKeyEditListVar,FinalKeyEditListVar,1
  551. Return FinalKeyEditListVar
  552. }
  553.  
  554.  
  555.  
  556. ; ---------------------------------------------
  557. ; Check If all keys are pressed simultaneously (If all keys are pressed returns 1, Else, returns 0)
  558. ; ---------------------------------------------
  559. XHotkeyAllKeysPressed(keysToBeChecked){
  560. Log("XHotkeyAllKeysPressed - Started, checking for these keys to be pressed: """ . keysToBeChecked . """",5)
  561. Loop, parse, keysToBeChecked, |, %A_Space%
  562. {
  563. ExitKeysPressed := true
  564. replace := {"~":"","*":"","$":""} ; removing modifiers before comparing keys
  565. keysToBeCheckedGroup := A_LoopField
  566. For what, with in replace
  567. {
  568. If InStr(keysToBeCheckedGroup,what)
  569. StringReplace, keysToBeCheckedGroup, keysToBeCheckedGroup, %what%, %with%, All
  570. }
  571. keysToBeCheckedGroup := RegexReplace( keysToBeCheckedGroup, "i)S:" ) ; removing options from keys
  572. keysToBeCheckedGroup := RegexReplace( keysToBeCheckedGroup, "i)H(.*):" ) ; removing options from keys
  573. keysToBeCheckedGroup := RegexReplace( keysToBeCheckedGroup, "i)D(.*):" ) ; removing options from keys
  574. keysToBeCheckedGroup := RegexReplace( keysToBeCheckedGroup, "i)T(.*):" ) ; removing options from keys
  575. keysToBeCheckedGroup := RegexReplace( keysToBeCheckedGroup, "^\s+|\s+$") ; keysToBeCheckedGroup without any spaces
  576. Loop, Parse, keysToBeCheckedGroup, &,%a_space%
  577. {
  578. If not (GetKeyState(A_LoopField,"p"))
  579. ExitKeysPressed := false
  580. }
  581. If ExitKeysPressed {
  582. Log("XHotkeyAllKeysPressed - Ended: Keys being checked were pressed",5)
  583. Return 1
  584. }
  585. }
  586. Log("XHotkeyAllKeysPressed - Ended: Keys being checked were not pressed",5)
  587. Return 0
  588. }
  589.  
  590.  
  591.  
  592.  
  593. ; ---------------------------------------------
  594. ; AUXILIAR FUNCTIONS
  595. ; ---------------------------------------------
  596. ; Functions Needed for sorting (by some strange motive If i try to use the autohotkey sort, it not work for ~Z & ~X and ~X & ~Z keys. I was only able to do the sorte by using the array library at http://www.autohotkey.com/forum/viewtopic.php?t=49736
  597. Array_Lib(p1="……", p2="……", p3="……", p4="……", p5="……", p6="……"){
  598. static ArrBase
  599. If !ArrBase
  600. ArrBase := Object("len", "Array_Length", "join", "Array_Join", "insert", "Array_Insert", "delete", "Array_Delete", "sort", "Array_sort", "append", "Array_Append")
  601. arr := Object("base", ArrBase)
  602. While (_:=p%A_Index%)!="……" && A_Index<=6
  603. arr[A_Index] := _
  604. Return arr
  605. }
  606. Array_Join(arr, sep="`n"){
  607. Loop, % arr.len()
  608. str .= arr[A_Index] sep
  609. StringTrimRight, str, str, % StrLen(sep)
  610. Return str
  611. }
  612. Array_Append(arr, p1="……", p2="……", p3="……", p4="……", p5="……", p6="……"){
  613. Return arr.insert(arr.len()+1, p1, p2, p3, p4, p5, p6)
  614. }
  615. Array_Insert(arr, index, p1="……", p2="……", p3="……", p4="……", p5="……", p6="……"){
  616. While (_:=p%A_Index%)!="……" && A_Index<=6
  617. arr._Insert(index + (A_Index-1), _)
  618. Return arr
  619. }
  620. Array_Sort(arr, func="Array_CompareFunc"){
  621. n := arr.len(), swapped := true
  622. while swapped {
  623. swapped := false
  624. Loop, % n-1 {
  625. i := A_Index
  626. If %func%(arr[i], arr[i+1], 1) > 0 ; standard ahk syntax for sort callout functions
  627. arr.insert(i, arr[i+1]).delete(i+2), swapped := true
  628. }
  629. n--
  630. }
  631. Return arr
  632. }
  633. Array_CompareFunc(a, b, c){
  634. Return a > b ? 1 : a = b ? 0 : -1
  635. }
  636. Array_Delete(arr, p1="……", p2="……", p3="……", p4="……", p5="……", p6="……"){
  637. While (_:=p%A_Index%)!="……" && A_Index<=6
  638. arr._Remove(_)
  639. Return arr
  640. }
  641. Array_Length(arr){
  642. len := arr._MaxIndex()
  643. Return len="" ? 0 : len
  644. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement