Advertisement
djvj

Untitled

Aug 2nd, 2015
396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 30.50 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. Log("XHotkeyTableCreation - Started",5)
  118. GoSubTimeDelay := 30 ; minimun time in miliseconds between key commands (necessary to avoid multiple gosub calls)
  119. LabelHoldCallDelay := 3000 ; minimun time in miliseconds between labels call after a hold call (necessary to avoid ghost label calls after an hold key press)
  120. KeyGroup := RegexReplace( KeyGroup, "^\s+|\s+$") ; KeyGroup without any spaces
  121. ;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)
  122. Keys := Array_Lib()
  123. Loop, Parse, KeyGroup, &,%a_space%
  124. {
  125. Keys.append(A_LoopField)
  126. }
  127. KeyGroup := Keys.sort().join("&")
  128. KeyGroupWithSpaces := KeyGroup
  129. If InStr(KeyGroup,"&")
  130. StringReplace, KeyGroupWithSpaces, KeyGroup, &, %a_space%&%a_space% ; KeyGroup with spaces between multiple keys to avoid autohotkey error in normal hotkey call
  131. If !XHotKeyTable
  132. XHotKeyTable:=[] ; create key table XHotKeyTable[TableNumber,keynumber,column]
  133. If KeyGroup not in %TableKeyGroups%
  134. {
  135. Log("XHotkeyTableCreation - KeyGroup " . KeyGroup . " not in TableKeyGroups " . TableKeyGroups,5)
  136. KeyGroupNumber++
  137. currentGroup := KeyGroupNumber
  138. currentkeyNumber := 0
  139. XHotKeyTable[currentGroup,1,1] := KeyGroup
  140. Loop, Parse, KeyGroup, &,%a_space%
  141. {
  142. currentkeyNumber++
  143. currentkey := RegexReplace( A_LoopField, "^\s+|\s+$" )
  144. XHotKeyTable[currentGroup,currentkeyNumber,2] := currentkey ; Store each exit key in column 3 as they are defined in the var
  145. XHotKeyTable[currentGroup,1,3] := currentkeyNumber ; number of keys in this group
  146. replace := {"~":"","*":"","$":""} ; Saving Keys without modifiers
  147. currentKeyClean := currentkey
  148. For what, with in replace
  149. {
  150. If InStr(currentKeyClean,what)
  151. StringReplace, currentKeyClean, currentKeyClean, %what%, %with%, All
  152. }
  153. XHotKeyTable[currentGroup,currentkeyNumber,4] := currentKeyClean
  154. }
  155. Log("XHotkeyTableCreation - Post loop 1 check",5)
  156. XHotKeyTable[currentGroup,1,5] := 0 ; initialize key press count for single, double and triple clicks
  157. XHotKeyTable[currentGroup,1,6] := LabelForSingleKey ; save label for single click
  158. XHotKeyTable[currentGroup,1,7] := LabelForHoldKey ; save label for press and hold
  159. XHotKeyTable[currentGroup,1,8] := KeyHoldWait ; save key hold wait time
  160. XHotKeyTable[currentGroup,1,9] := LabelForDoubleClick ; save label for double click
  161. XHotKeyTable[currentGroup,1,10] := LabelForMoreThanTwoClicks ; save label for three or more clicks
  162. XHotKeyTable[currentGroup,1,11] := DoubleClickKeyWait ; save label for double click time between keys
  163. If not InStr(options, "OFF"){
  164. If LabelForSingleKey
  165. XHotKeyTable[currentGroup,1,13] := true
  166. If LabelForHoldKey
  167. XHotKeyTable[currentGroup,2,13] := true
  168. If LabelForDoubleClick
  169. XHotKeyTable[currentGroup,3,13] := true
  170. If LabelForMoreThanTwoClicks
  171. XHotKeyTable[currentGroup,4,13] := true
  172. } Else {
  173. If LabelForSingleKey
  174. XHotKeyTable[currentGroup,1,13] := false
  175. If LabelForHoldKey
  176. XHotKeyTable[currentGroup,2,13] := false
  177. If LabelForDoubleClick
  178. XHotKeyTable[currentGroup,3,13] := false
  179. If LabelForMoreThanTwoClicks
  180. XHotKeyTable[currentGroup,4,13] := false
  181. }
  182. Log("XHotkeyTableCreation - Post loop 2 check",5)
  183. 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
  184. 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)
  185. Hotkey, % KeyGroupWithSpaces, %LabelForSingleKey%, %Options% ; normal hotkey command
  186. } 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
  187. 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)
  188. Loop, Parse, KeyGroup, &,%a_space%
  189. {
  190. Hotkey, % XHotKeyTable[currentGroup,A_Index,2], HotKeyModeProcess, %Options% ; go to sub to test multiple key press If any exit emulator key is pressed
  191. XHotKeyTable[currentGroup,1,12] := true
  192. }
  193. }
  194. TableKeyGroups .= KeyGroup . ","
  195. Log("XHotkeyTableCreation - Ended",5)
  196. Return XHotKeyTable
  197. } Else {
  198. Log("XHotkeyTableCreation - KeyGroup " . KeyGroup . " is in TableKeyGroups " . TableKeyGroups,5)
  199. currentGroup:=0
  200. Loop, %KeyGroupNumber%
  201. {
  202. currentGroup++
  203. currentKeysonKeyGroup := XHotKeyTable[currentGroup,1,1]
  204. If (currentKeysonKeyGroup = KeyGroup){
  205. Break
  206. }
  207. }
  208. Log("XHotkeyTableCreation - Post loop 10 check",5)
  209. If not InStr(options, "OFF"){
  210. If LabelForSingleKey
  211. XHotKeyTable[currentGroup,1,13] := true
  212. If LabelForHoldKey
  213. XHotKeyTable[currentGroup,2,13] := true
  214. If LabelForDoubleClick
  215. XHotKeyTable[currentGroup,3,13] := true
  216. If LabelForMoreThanTwoClicks
  217. XHotKeyTable[currentGroup,4,13] := true
  218. } Else {
  219. If LabelForSingleKey
  220. XHotKeyTable[currentGroup,1,13] := false
  221. If LabelForHoldKey
  222. XHotKeyTable[currentGroup,2,13] := false
  223. If LabelForDoubleClick
  224. XHotKeyTable[currentGroup,3,13] := false
  225. If LabelForMoreThanTwoClicks
  226. XHotKeyTable[currentGroup,4,13] := false
  227. }
  228. If not InStr(options, "OFF"){
  229. If LabelForSingleKey
  230. If (XHotKeyTable[currentGroup,1,6] <> LabelForSingleKey)
  231. XHotKeyTable[currentGroup,1,6] := LabelForSingleKey ; update label for single click
  232. If LabelForHoldKey
  233. If XHotKeyTable[currentGroup,1,7] <> LabelForHoldKey
  234. XHotKeyTable[currentGroup,1,7] := LabelForHoldKey ; update label for press and hold
  235. If KeyHoldWait
  236. If XHotKeyTable[currentGroup,1,8] <> KeyHoldWait
  237. XHotKeyTable[currentGroup,1,8] := KeyHoldWait ; update key hold wait time
  238. If LabelForDoubleClick
  239. If XHotKeyTable[currentGroup,1,9] <> LabelForDoubleClick
  240. XHotKeyTable[currentGroup,1,9] := LabelForDoubleClick ; update label for double click
  241. If LabelForMoreThanTwoClicks
  242. If XHotKeyTable[currentGroup,1,10] <> LabelForMoreThanTwoClicks
  243. XHotKeyTable[currentGroup,1,10] := LabelForMoreThanTwoClicks ; update label for three or more clicks
  244. If DoubleClickKeyWait
  245. If XHotKeyTable[currentGroup,1,11] <> DoubleClickKeyWait
  246. XHotKeyTable[currentGroup,1,11] := DoubleClickKeyWait ; update label for double click time between keys
  247. }
  248. If not XHotKeyTable[currentGroup,1,12] ; disabling previous normal hotkey command If previously defined
  249. { Hotkey, %KeyGroupWithSpaces%, Off
  250. Log("XHotkeyTableCreation - Disabled Hotkey for: """ . KeyGroupWithSpaces . """",5)
  251. }
  252. Log("XHotkeyTableCreation - Post loop 11 check",5)
  253. 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
  254. 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)
  255. Hotkey, % KeyGroupWithSpaces, %LabelForSingleKey%, %Options% ; normal hotkey command
  256. } 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
  257. 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)
  258. Loop, Parse, KeyGroup, &,%a_space%
  259. {
  260. Hotkey, % XHotKeyTable[currentGroup,A_Index,2], HotKeyModeProcess, %Options% ; go to sub to test multiple key press If any exit emulator key is pressed
  261. XHotKeyTable[currentGroup,1,12] := true
  262. }
  263. }
  264. Log("XHotkeyTableCreation - Post loop 12 check",5)
  265. If not InStr(options, "OFF")
  266. If ForceHoldKeysList
  267. forceHoldKey(ForceHoldKeysList)
  268. Log("XHotkeyTableCreation - Ended",5)
  269. Return
  270. }
  271. }
  272.  
  273. HotKeyModeProcess:
  274. If (A_TickCount < LastHotKeyModeProcessTime+GoSubTimeDelay) ; XHotkeyMinimunDelay necessary to avoid multiple calls to subs in multiple Key groups
  275. Return
  276. LastHotKeyModeProcessTime := A_TickCount
  277. currentkey := A_ThisHotkey ; current pressed keys
  278. replace := {"~":"","*":"","$":""} ; Saving current Key without modifiers to use on Keywait
  279. For what, with in replace
  280. {
  281. If InStr(currentkey,what)
  282. StringReplace, currentkey, currentkey, %what%, %with%, All
  283. }
  284. currentGroup:=0
  285. Loop, %KeyGroupNumber%
  286. {
  287. currentGroup++
  288. If XHotKeyTable[currentGroup,1,12]
  289. {
  290. If AllKeysPressed(currentGroup) {
  291. CurrentPressandHoldLabel := % XHotKeyTable[currentGroup,1,7]
  292. CurrentKeyHoldWait := % XHotKeyTable[currentGroup,1,8]
  293. If %CurrentPressandHoldLabel%
  294. KeyWait, %currentKey%, t%currentKeyHoldWait%
  295. Else
  296. KeyWait, %currentKey%
  297. If (GetKeyState(currentKey,"p")) ; could be a hold key press
  298. {
  299. If IsLabel(CurrentPressandHoldLabel)
  300. If XHotKeyTable[currentGroup,2,13]
  301. If (A_TickCount > lastHoldLabelCall + LabelHoldCallDelay)
  302. {
  303. lastHoldLabelCall := A_TickCount
  304. Log("1",3)
  305. Gosub, %CurrentPressandHoldLabel%
  306. }
  307. LastGoSubTime := A_TickCount
  308. currentHoldKeyPressed := currentKey
  309. SetTimer, checkHoldKeyUp, 50
  310. XHotKeyTable[currentGroup,1,5] := 0 ; reset the count to prepare for the next series of presses
  311. Return
  312. } Else {
  313. If (XHotKeyTable[currentGroup,1,5]) > 0 { ; SetTimer already started, so we log the keypress instead
  314. If (IgnoreMultipleKeys>0) { ; necessary to avoid multiple key count in multiple Key groups
  315. IgnoreMultipleKeys--
  316. Return
  317. }
  318. IgnoreMultipleKeys := XHotKeyTable[currentGroup,1,3]-1
  319. XHotKeyTable[currentGroup,1,5]++
  320. Return
  321. }
  322. XHotKeyTable[currentGroup,1,5] := 1 ; Otherwise, this is the first press of a new series. Set count to 1 and start the timer:
  323. ActiveCurrentGroup := currentGroup
  324. CurrentDoubleClickKeyWait := % XHotKeyTable[ActiveCurrentGroup,1,11]
  325. If XHotKeyTable[ActiveCurrentGroup,1,9] or XHotKeyTable[ActiveCurrentGroup,1,10] {
  326. If XHotKeyTable[currentGroup,3,13] or XHotKeyTable[currentGroup,4,13]
  327. SetTimer, MultipleClickCheck, %CurrentDoubleClickKeyWait% ; Wait for more presses within a CurrentDoubleClickKeyWait millisecond time.
  328. Return
  329. } Else {
  330. CurrentSinglePressLabel := % XHotKeyTable[ActiveCurrentGroup,1,6]
  331. If IsLabel(CurrentSinglePressLabel)
  332. {
  333. If XHotKeyTable[currentGroup,1,13]
  334. If (A_TickCount > lastHoldLabelCall + LabelHoldCallDelay)
  335. { Log("2",3)
  336.  
  337. Gosub %CurrentSinglePressLabel%
  338. }
  339. LastGoSubTime := A_TickCount
  340. }
  341. XHotKeyTable[ActiveCurrentGroup,1,5] := 0 ; reset the count to prepare for the next series of presses
  342. }
  343. Return
  344. }
  345. }
  346. }
  347. }
  348. Return
  349.  
  350. checkHoldKeyUp:
  351. If !(GetKeyState(currentHoldKeyPressed,"p"))
  352. SetTimer, checkHoldKeyUp, off
  353. Return
  354.  
  355. MultipleClickCheck: ;checking If the key group was pressed once, twice or more times.
  356. SetTimer, MultipleClickCheck, off
  357. CurrentSinglePressLabel := % XHotKeyTable[ActiveCurrentGroup,1,6]
  358. CurrentDoubleClickLabel := % XHotKeyTable[ActiveCurrentGroup,1,9]
  359. CurrentLabelForMoreThanTwoClicks := % XHotKeyTable[ActiveCurrentGroup,1,10]
  360. If (XHotKeyTable[ActiveCurrentGroup,1,5] > 2) and (IsLabel(CurrentLabelForMoreThanTwoClicks)) { ; The key was pressed three or more times.
  361. If XHotKeyTable[currentGroup,4,13]
  362. If (A_TickCount > lastHoldLabelCall + LabelHoldCallDelay) {
  363. Log("3",3)
  364.  
  365. Gosub, %CurrentLabelForMoreThanTwoClicks%
  366. }
  367. LastGoSubTime := A_TickCount
  368. } Else If (XHotKeyTable[ActiveCurrentGroup,1,5] > 1) and (IsLabel(CurrentDoubleClickLabel)) { ; The key was pressed twice.
  369. If XHotKeyTable[currentGroup,3,13]
  370. If (A_TickCount > lastHoldLabelCall + LabelHoldCallDelay) {
  371. Log("4",3)
  372. Gosub, %CurrentDoubleClickLabel%
  373. }
  374. LastGoSubTime := A_TickCount
  375. } Else {
  376. If IsLabel(CurrentSinglePressLabel)
  377. If XHotKeyTable[currentGroup,1,13]
  378. If (A_TickCount > lastHoldLabelCall + LabelHoldCallDelay) {
  379. Log("5",3)
  380. Gosub %CurrentSinglePressLabel%
  381. }
  382. LastGoSubTime := A_TickCount
  383. }
  384. XHotKeyTable[ActiveCurrentGroup,1,5] := 0 ; reset the count to prepare for the next series of presses
  385. Return
  386.  
  387.  
  388. AllKeysPressed(currentKeygroup) { ; function to check If the keys are pressed simultneously
  389. Global
  390. ExitKeysPressed := true
  391. Loop, % XHotKeyTable[currentKeygroup,1,3]
  392. {
  393. If XHotKeyTable[currentKeygroup,A_index,4]
  394. If not (GetKeyState(XHotKeyTable[currentKeygroup,A_index,4],"p"))
  395. ExitKeysPressed := false
  396. }
  397. If ExitKeysPressed
  398. Return 1
  399. Return 0
  400. }
  401.  
  402.  
  403. ; ---------------------------------------------
  404. ; FORCEHOLDKEY FUNCTION CODE
  405. ; ---------------------------------------------
  406. ForceHoldKey(FullKeyHoldList,KeyHoldWait="1") { ; function to force hold press mode for any Hotkey
  407. Global
  408. Log("ForceHoldKey - Started",5)
  409. ForceHoldKeysList .= FullKeyHoldList . "|"
  410. StringTrimRight,TableKeysAux,TableKeyGroups,1
  411. Loop, parse, TableKeysAux, `,, %A_Space%
  412. {
  413. KeysArray%A_Index% := A_Loopfield
  414. }
  415. Log("ForceHoldKey - Check 1",5)
  416. replace := {"~":"","*":"","$":""} ; removing modifiers before comparing keys
  417. Log("ForceHoldKey - Check 1a TableKeysAux: " . TableKeysAux,5)
  418. For what, with in replace
  419. {
  420. If InStr(TableKeysAux,what)
  421. StringReplace, TableKeysAux, TableKeysAux, %what%, %with%, All
  422. }
  423. Log("ForceHoldKey - Check 1b TableKeysAux: " . TableKeysAux,5)
  424. Log("ForceHoldKey - Check 2 FullKeyHoldList: " . FullKeyHoldList,5)
  425. Loop, parse, FullKeyHoldList, |, %A_Space%
  426. {
  427. Log("ForceHoldKey - Check 3 - " . A_Index . " - A_LoopField: " . A_LoopField,5)
  428. KeyHoldListGroup := A_LoopField
  429. KeyHoldListGroup := RegexReplace( KeyHoldListGroup, "i)S:" ) ; removing options from keys
  430. KeyHoldListGroup := RegexReplace( KeyHoldListGroup, "i)H(.*):" ) ; removing options from keys
  431. KeyHoldListGroup := RegexReplace( KeyHoldListGroup, "i)D(.*):" ) ; removing options from keys
  432. KeyHoldListGroup := RegexReplace( KeyHoldListGroup, "i)T(.*):" ) ; removing options from keys
  433. KeyHoldListGroup := RegexReplace( KeyHoldListGroup, "^\s+|\s+$") ; KeyGroup without any spaces
  434. ;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)
  435. Keys := Array_Lib()
  436. Loop, Parse, KeyHoldListGroup, &,%a_space%
  437. {
  438. Keys.append(A_LoopField)
  439. Log("ForceHoldKey - Check 4 - " . A_Index . " - A_LoopField: " . A_LoopField,5)
  440. }
  441. KeyHoldListGroup := Keys.sort().join("&")
  442. replace := {"~":"","*":"","$":""} ; removing modifiers before comparing keys
  443. For what, with in replace
  444. {
  445. If InStr(KeyHoldListGroup,what)
  446. StringReplace, KeyHoldListGroup, KeyHoldListGroup, %what%, %with%, All
  447. }
  448. Loop, Parse, TableKeysAux, `,,%a_space%
  449. {
  450. If (KeyHoldListGroup = A_LoopField) { ; Key to force hold mode is in the keys defined by the user
  451. Log("ForceHoldKey - Check 4 --- " . A_Index . " - A_LoopField: " . A_LoopField,5)
  452. currentComboKey := % KeysArray%A_Index%
  453. If InStr(currentComboKey,"&")
  454. StringReplace, currentComboKey, currentComboKey, &, %a_space%&%a_space% ; KeyGroup with spaces between multiple keys to avoid autohotkey error in normal hotkey call
  455. If not XHotKeyTable[A_index,1,12] ; disabling normal hotkey command If previously defined
  456. Hotkey, %currentComboKey%, Off
  457. Loop, Parse, currentComboKey, &,%a_space%
  458. {
  459. Log("ForceHoldKey - Check 5 ---HotKeyModeProcess Change to On--- " . A_Index . " - A_LoopField: " . A_LoopField,5)
  460. Hotkey, %A_LoopField%, HotKeyModeProcess, On
  461. }
  462. XHotKeyTable[A_index,1,12] := true ; enabling XHotKey mode in table
  463. XHotKeyTable[A_index,1,13] := "" ; disabling single press key
  464. XHotKeyTable[A_index,2,13] := true ; enabling press and hold key
  465. XHotKeyTable[A_index,3,13] := "" ; disabling double press key
  466. XHotKeyTable[A_index,4,13] := "" ; disabling three or more presses key
  467. If XHotKeyTable[A_index,1,6] ; assigning single press label to press and hold If existent
  468. XHotKeyTable[A_index,1,7] := XHotKeyTable[A_index,1,6]
  469. Else If XHotKeyTable[A_index,1,9] ; Else assigning double press label to press and hold If existent
  470. XHotKeyTable[A_index,1,7] := XHotKeyTable[A_index,1,9]
  471. Else If XHotKeyTable[A_index,1,10] ; Else assigning three or more presses label to press and hold If existent
  472. XHotKeyTable[A_index,1,7] := XHotKeyTable[A_index,1,10]
  473. XHotKeyTable[A_index,1,6] := "" ; erasing single press label
  474. If not XHotKeyTable[A_index,1,8] ; determining hold wait time If not previously defined
  475. XHotKeyTable[A_index,1,8] := KeyHoldWait
  476. XHotKeyTable[A_index,1,9] := "" ; erasing double press label
  477. XHotKeyTable[A_index,1,10] := "" ; erasing three or more presses label
  478. XHotKeyTable[A_index,1,9] := "" ; erasing double press wait
  479. }
  480. }
  481.  
  482. }
  483. Log("ForceHoldKey - Ended",5)
  484. Return
  485. }
  486.  
  487.  
  488. ; ---------------------------------------------
  489. ; XHOTKEYVAREDIT FUNCTION
  490. ; ---------------------------------------------
  491. xHotKeyVarEdit(KeyEditList,KeyEditListVar,Keymodifier="",action="") {
  492. Loop, parse, %KeyEditListVar%, |, %A_Space%
  493. {
  494. initialKeyEditListGroup := A_LoopField
  495. replace := {"~":"","*":"","$":""} ; removing modifiers before comparing keys
  496. currentVarKeyGroup := A_LoopField
  497. For what, with in replace
  498. {
  499. If InStr(currentVarKeyGroup,what)
  500. StringReplace, currentVarKeyGroup, currentVarKeyGroup, %what%, %with%, All
  501. }
  502. currentVarKeyGroup := RegexReplace( currentVarKeyGroup, "i)S:" ) ; removing options from keys
  503. currentVarKeyGroup := RegexReplace( currentVarKeyGroup, "i)H(.*):" ) ; removing options from keys
  504. currentVarKeyGroup := RegexReplace( currentVarKeyGroup, "i)D(.*):" ) ; removing options from keys
  505. currentVarKeyGroup := RegexReplace( currentVarKeyGroup, "i)T(.*):" ) ; removing options from keys
  506. currentVarKeyGroup := RegexReplace( currentVarKeyGroup, "^\s+|\s+$") ; KeyGroup without any spaces
  507. Keys := Array_Lib()
  508. Loop, Parse, currentVarKeyGroup, &,%a_space%
  509. {
  510. Keys.append(A_LoopField)
  511. }
  512. currentVarKeyGroup := Keys.sort().join("&")
  513. groupChecked := false
  514. Loop, parse, KeyEditList, |, %A_Space%
  515. {
  516. currentKeyEditListGroup := A_LoopField
  517. replace := {"~":"","*":"","$":""} ; removing modifiers before comparing keys
  518. KeyEditListGroup := A_LoopField
  519. For what, with in replace
  520. {
  521. If InStr(KeyEditListGroup,what)
  522. StringReplace, KeyEditListGroup, KeyEditListGroup, %what%, %with%, All
  523. }
  524. KeyEditListGroup := RegexReplace( KeyEditListGroup, "i)S:" ) ; removing options from keys
  525. KeyEditListGroup := RegexReplace( KeyEditListGroup, "i)H(.*):" ) ; removing options from keys
  526. KeyEditListGroup := RegexReplace( KeyEditListGroup, "i)D(.*):" ) ; removing options from keys
  527. KeyEditListGroup := RegexReplace( KeyEditListGroup, "i)T(.*):" ) ; removing options from keys
  528. KeyEditListGroup := RegexReplace( KeyEditListGroup, "^\s+|\s+$") ; KeyGroup without any spaces
  529. Keys := Array_Lib()
  530. Loop, Parse, KeyEditListGroup, &,%a_space%
  531. {
  532. Keys.append(A_LoopField)
  533. }
  534. KeyEditListGroup := Keys.sort().join("&")
  535. If (KeyEditListGroup = currentVarKeyGroup){
  536. currentEditKey :=
  537. Loop, Parse, initialKeyEditListGroup, &,%a_space%
  538. {
  539. currentEditKey := A_LoopField
  540. If(action="Remove"){
  541. If InStr(currentEditKey,Keymodifier)
  542. StringReplace, currentEditKey, currentEditKey, %Keymodifier%, , all
  543. }
  544. If(action="Add"){
  545. ReverseKeyEdit := DelimitedReversal(currentEditKey,"`:")
  546. Loop, parse, ReverseKeyEdit, `:, %A_Space%
  547. {
  548. currentfield := A_LoopField
  549. If (a_index = 1) {
  550. If not InStr(currentfield,Keymodifier)
  551. currentEditKey := Keymodifier . currentfield
  552. Else
  553. currentEditKey := currentfield
  554. } Else {
  555. currentEditKey := currentfield . ":" . currentEditKey
  556. }
  557. }
  558. }
  559. currentKeyEditListVar := currentKeyEditListVar . "&" . currentEditKey
  560. groupChecked := true
  561. }
  562. }
  563. }
  564. If not groupChecked
  565. currentKeyEditListVar := "&" . initialKeyEditListGroup
  566. StringTrimLeft,currentKeyEditListVar,currentKeyEditListVar,1
  567. FinalKeyEditListVar := FinalKeyEditListVar . "|" . currentKeyEditListVar
  568. currentKeyEditListVar := ""
  569. }
  570. StringTrimLeft,FinalKeyEditListVar,FinalKeyEditListVar,1
  571. Return FinalKeyEditListVar
  572. }
  573.  
  574.  
  575.  
  576. ; ---------------------------------------------
  577. ; Check If all keys are pressed simultaneously (If all keys are pressed returns 1, Else, returns 0)
  578. ; ---------------------------------------------
  579. XHotkeyAllKeysPressed(keysToBeChecked){
  580. Log("XHotkeyAllKeysPressed - Started, checking for these keys to be pressed: """ . keysToBeChecked . """",5)
  581. Loop, parse, keysToBeChecked, |, %A_Space%
  582. {
  583. ExitKeysPressed := true
  584. replace := {"~":"","*":"","$":""} ; removing modifiers before comparing keys
  585. keysToBeCheckedGroup := A_LoopField
  586. For what, with in replace
  587. {
  588. If InStr(keysToBeCheckedGroup,what)
  589. StringReplace, keysToBeCheckedGroup, keysToBeCheckedGroup, %what%, %with%, All
  590. }
  591. keysToBeCheckedGroup := RegexReplace( keysToBeCheckedGroup, "i)S:" ) ; removing options from keys
  592. keysToBeCheckedGroup := RegexReplace( keysToBeCheckedGroup, "i)H(.*):" ) ; removing options from keys
  593. keysToBeCheckedGroup := RegexReplace( keysToBeCheckedGroup, "i)D(.*):" ) ; removing options from keys
  594. keysToBeCheckedGroup := RegexReplace( keysToBeCheckedGroup, "i)T(.*):" ) ; removing options from keys
  595. keysToBeCheckedGroup := RegexReplace( keysToBeCheckedGroup, "^\s+|\s+$") ; keysToBeCheckedGroup without any spaces
  596. Loop, Parse, keysToBeCheckedGroup, &,%a_space%
  597. {
  598. If not (GetKeyState(A_LoopField,"p"))
  599. ExitKeysPressed := false
  600. }
  601. If ExitKeysPressed {
  602. Log("XHotkeyAllKeysPressed - Ended: Keys being checked were pressed",5)
  603. Return 1
  604. }
  605. }
  606. Log("XHotkeyAllKeysPressed - Ended: Keys being checked were not pressed",5)
  607. Return 0
  608. }
  609.  
  610.  
  611.  
  612.  
  613. ; ---------------------------------------------
  614. ; AUXILIAR FUNCTIONS
  615. ; ---------------------------------------------
  616. ; 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
  617. Array_Lib(p1="……", p2="……", p3="……", p4="……", p5="……", p6="……"){
  618. static ArrBase
  619. If !ArrBase
  620. ArrBase := Object("len", "Array_Length", "join", "Array_Join", "insert", "Array_Insert", "delete", "Array_Delete", "sort", "Array_sort", "append", "Array_Append")
  621. arr := Object("base", ArrBase)
  622. While (_:=p%A_Index%)!="……" && A_Index<=6
  623. arr[A_Index] := _
  624. Return arr
  625. }
  626. Array_Join(arr, sep="`n"){
  627. Loop, % arr.len()
  628. str .= arr[A_Index] sep
  629. StringTrimRight, str, str, % StrLen(sep)
  630. Return str
  631. }
  632. Array_Append(arr, p1="……", p2="……", p3="……", p4="……", p5="……", p6="……"){
  633. Return arr.insert(arr.len()+1, p1, p2, p3, p4, p5, p6)
  634. }
  635. Array_Insert(arr, index, p1="……", p2="……", p3="……", p4="……", p5="……", p6="……"){
  636. While (_:=p%A_Index%)!="……" && A_Index<=6
  637. arr._Insert(index + (A_Index-1), _)
  638. Return arr
  639. }
  640. Array_Sort(arr, func="Array_CompareFunc"){
  641. n := arr.len(), swapped := true
  642. while swapped {
  643. swapped := false
  644. Loop, % n-1 {
  645. i := A_Index
  646. If %func%(arr[i], arr[i+1], 1) > 0 ; standard ahk syntax for sort callout functions
  647. arr.insert(i, arr[i+1]).delete(i+2), swapped := true
  648. }
  649. n--
  650. }
  651. Return arr
  652. }
  653. Array_CompareFunc(a, b, c){
  654. Return a > b ? 1 : a = b ? 0 : -1
  655. }
  656. Array_Delete(arr, p1="……", p2="……", p3="……", p4="……", p5="……", p6="……"){
  657. While (_:=p%A_Index%)!="……" && A_Index<=6
  658. arr._Remove(_)
  659. Return arr
  660. }
  661. Array_Length(arr){
  662. len := arr._MaxIndex()
  663. Return len="" ? 0 : len
  664. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement