Advertisement
Lorenzo501

Critical/Sleep Event Test (2)

Mar 18th, 2025 (edited)
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.94 KB | None | 0 0
  1. THESE ARE A BUNCH OF MESSY BRAINSTORM/TEST NOTES TO TRY AND UNDERSTAND CRITICAL BETTER, FOR NOW I'LL BE USING CRITICAL ONLY WHEN ABSOLUTELY NECESSARY. WHICH SEEMS ONLY TO BE THE CASE FOR HOTKEYS AND TIMERS INTERRUPTING OTHER THREADS. COULD DO THE INITIAL TESTS AGAIN TO MAKE SURE I DIDN'T FORGET ANYTHING. BUT I'M SURE I HAVE IT FIGURED OUT ALREADY, SO I'LL JUST SKIP DIGGING INTO THE INITIAL TESTS AGAIN FOR NOW (MAYBE I'LL DO IT LATER). CRITICAL SEEMS RATHER USELESS FOR WINEVENT HANDLERS
  2.  
  3.  
  4. /********** TRASH: `...txt` (part of initial test files) **********/
  5.  
  6. I do not think that there will be issues, not even without Critical b/c the sleep used in either fullscreen mark feature does not affect it, since it's the first action, only the thread
  7. being busy could let it get overtaken but it doesn't do much so that is like basically impossible.. Still, I could just do Critical everywhere to stay consistent so there won't ever be a
  8. problem, not even when I decide to expand stuff and then suddenly do need it. So use Critical and do not use the bool now all of the sudden! Only Critical(-1) in the workaround
  9.  
  10.  
  11. [pretty sure Critical will only affect busy-wait to make it not get interrupted when it's busy, doesn't affect sleep at all it seems and sleep lets it get interrupted by new threads but not
  12. threads that got paused while a new thread took over. So if you use both busy-wait and sleep, then sleep will let it get interrupted in the way I just described, because it isn't protected
  13. by Critical, the busy-wait is just extra then so that won't make the sleep suddenly protected as well..]
  14.  
  15. we'll do critical I guess, so just make the new fullscreen mark-toggle feature first and then we'll see what it needs exactly?
  16.  
  17. /********** TRASH: `Critical(-1) in event handlers.txt` (part of initial test files) **********/
  18.  
  19. I might wanna add Critical(-1) to all my event handlers above the isScopeEntered condition set instruction, b/c it does seem to help while there are no Sleep nor A_WinDelay/WinWait
  20. so it's always good, can try the pastebin again just to be sure
  21.  
  22. Critical/Sleep Event Test.ahk
  23.  
  24. Add comment to the Critical(-1) that it only works on overtakes 'in event handlers', not win delays, nor Sleep() and WinWait(). So the condition is only for in case win delays, Sleep() or
  25. WinWait() gets added (or to discard queued events but that'd be done with Sleep() as well). I'm 100% positive that Critical(-1) in non-event threads such as a hotkey thread, makes it
  26. actually work for Sleep() as well. Though not sure what happens in mouse event handlers (mouse hook is irrelevant, already has Critical in it), perhaps the same as win event handlers
  27.  
  28.  
  29. is the event handler bool still necessary if critical is enabled? o.o [YES, good to consistently put it in there for any interruptions that Critical has no effect on]
  30.  
  31.  
  32.  
  33.  
  34. don't forget WinEvent Monitor, GW2, and some scripts on the 2nd github acc and pastebin (such as magic bullet)
  35.  
  36.  
  37.  
  38.  
  39. be careful with WinEvent handlers that take a lot of time to execute, with other code such as hotkeys.. because if for example a hotkey starts and then waits,
  40. then if a WinEvent runs for a long time, that hotkey won't be able to continue until the WinEvent waits as well or ends.. just an edge case, all WinEvent handlers are probably fast.
  41. the HDR subs fix > loop btn fix also has a WinEvent handler but that one is so fast it didn't even need a LButton and Enter hotkey for protection, and if it did; does not actually hinder
  42. the LButton and Enter hotkey.. unless ofc if you make it intentionally take a long time
  43.  
  44. /********** TRASH: `test - Copy.ahk` (part of initial test files) **********/
  45.  
  46. #Requires AutoHotkey 2.0
  47. Persistent()
  48. A_CoordModeToolTip := "Screen"
  49.  
  50. EVENT_SYSTEM_FOREGROUND := 0x0003
  51. EVENT_OBJECT_SHOW := 0x8002
  52. text := ""
  53.  
  54. HookEvent(EVENT_SYSTEM_FOREGROUND, HandleActivatedWindowTaskbarEvent)
  55. HookEvent(EVENT_OBJECT_SHOW, HandleShowedFullscreenWinEvent)
  56.  
  57. HandleActivatedWindowTaskbarEvent(hWinEventHook, event, hWnd, *)
  58. {
  59. static count := 0
  60.  
  61. try
  62. {
  63. Critical(-1) ; (W/ BUSY-WAIT) 1 1 2 2 3 3 when uncommented, 1 2 3 3 2 1 when commented-out
  64. global text .= " ^^f" (id := ++count)
  65. Tooltip(text)
  66. loop (8000000) ; Approx. 2sec busy-wait (has approx. 30% CPU usage at most)
  67. continue
  68. ;loop (4)
  69. ; Sleep(200) ;Sleep(-1) ; (W/ CRITICAL ON) 1 2 3 3 2 1 when uncommented, 1 1 2 2 3 3 when commented-out
  70. ;,
  71. Tooltip(text .= " ^^f" id)
  72. }
  73. }
  74.  
  75. HandleShowedFullscreenWinEvent(hWinEventHook, event, hWnd, *)
  76. {
  77. static count := 0
  78.  
  79. try
  80. {
  81. Critical(-1) ; (W/ BUSY-WAIT) 1 1 2 2 3 3 when uncommented, 1 2 3 3 2 1 when commented-out
  82. global text .= " __s" (id := ++count)
  83. Tooltip(text)
  84. loop (8000000) ; Approx. 2sec busy-wait (has approx. 30% CPU usage at most)
  85. continue
  86. ;loop (4)
  87. ; Sleep(200) ;Sleep(-1) ; (W/ CRITICAL ON) 1 2 3 3 2 1 when uncommented, 1 1 2 2 3 3 when commented-out
  88. ;,
  89. Tooltip(text .= " __s" id)
  90. }
  91. }
  92.  
  93. HookEvent(event, fnObj, pid := 0) => DllCall("SetWinEventHook", "UInt", event, "UInt", event, "Ptr", 0, "Ptr", CallbackCreate(fnObj), "UInt", pid, "UInt", 0, "UInt", 0)
  94.  
  95. /********** TRASH: `test..ahk` (part of initial test files) **********/
  96.  
  97. #Requires AutoHotkey 2.0
  98. Persistent()
  99. A_CoordModeToolTip := "Screen"
  100.  
  101. EVENT_SYSTEM_FOREGROUND := 0x0003
  102. EVENT_OBJECT_SHOW := 0x8002
  103. txt := "", cnt1 := 0, cnt2 := 0, isBusy1 := false, isBusy2 := false
  104.  
  105. HookEvent(EVENT_SYSTEM_FOREGROUND, HandleActivatedWindowTaskbarEvent)
  106. HookEvent(EVENT_OBJECT_SHOW, HandleShowedFullscreenWinEvent)
  107.  
  108. F1::
  109. {
  110. global isBusy1 := false
  111. global isBusy2 := false
  112. global cnt1 := 0
  113. global cnt2 := 0
  114. }
  115.  
  116. HandleActivatedWindowTaskbarEvent(hWinEventHook, event, hWnd, *)
  117. {
  118. static cnt := 0
  119. ;Critical(-1)
  120. ;Sleep(30)
  121.  
  122. if (!isBusy1)
  123. {
  124. global isBusy1 := true
  125. tooltip("?")
  126. ;cnt := 0
  127.  
  128. loop
  129. {
  130. global cnt1 := cnt1 + 1
  131.  
  132. if (cnt1 = 5)
  133. break
  134.  
  135. Sleep(200)
  136. global txt .= cnt1 " Foreground`t" hWnd "`n"
  137. Tooltip(txt, 1000, 1000)
  138. }
  139. }
  140. ;global txt .= "Foreground`n"
  141. ;tooltip(txt, 1000, 1000)
  142.  
  143. else
  144. {
  145. ++cnt
  146. global txt .= cnt " __Foreground`t" hWnd "`n"
  147. tooltip(txt, 1000, 1000)
  148. }
  149. }
  150.  
  151. HandleShowedFullscreenWinEvent(hWinEventHook, event, hWnd, *)
  152. {
  153. static cnt := 0
  154. ;Critical(-1)
  155. ;Sleep(200)
  156.  
  157. if (!isBusy2)
  158. {
  159. global isBusy2 := true
  160. tooltip("??")
  161. ;cnt := 0
  162.  
  163. loop
  164. {
  165. global cnt2 := cnt2 + 1
  166.  
  167. if (cnt2 = 5)
  168. break
  169.  
  170. Sleep(200)
  171. global txt .= cnt2 " Show`t`t" hWnd "`n"
  172. Tooltip(txt, 1000, 1000)
  173. }
  174. }
  175. ;global txt .= "Show`n"
  176. ;tooltip(txt, 1000, 1000)
  177.  
  178. else
  179. {
  180. ++cnt
  181. global txt .= cnt " __Show`t" hWnd "`n"
  182. tooltip(txt, 1000, 1000)
  183. }
  184. }
  185.  
  186. HookEvent(event, fnObj, pid := 0) => DllCall("SetWinEventHook", "UInt", event, "UInt", event, "Ptr", 0, "Ptr", CallbackCreate(fnObj), "UInt", pid, "UInt", 0, "UInt", 0)
  187.  
  188. /********** TRASH: `README.txt` (part of latest test files) **********/
  189.  
  190. in Time Saver I can use FIND and then Event(
  191. there PUT AT THE FIRST LINE OF THE WINEVENT HANDLER (it is best to put it there, do not put it at the first line of the if statement scope..)
  192. Critical(-1) ; Enables only the Critical mode of the thread made for this specific WinEvent handler (buffers hotkeys and timers until Critical is disabled or the thread finishes)
  193.  
  194.  
  195. however there's a WinEvent handler that uses a temporary hotkey, which must not have Critical
  196.  
  197.  
  198.  
  199.  
  200.  
  201. I think it won't help the WinEvent Monitor at all, b/c it only has an effect on interruptions by hotkeys and timers
  202. it will also make WinEvent handlers take a tiny bit longer to execute the rest of the code, b/c it'd have to execute the Critical(-1) first, which is likely only bad in MTO though but still
  203. and b/c hotkeys will get buffered, that might very well cause key-press lag.. which would likely be pretty annoying with the LButton hotkeys
  204. pretty sure it's better to just leave it out and keep everything fast, I doubt very much that anything will go wrong because of it
  205. but I can still keep it in WinEvent handlers that absolutely need it, such as:
  206. HandleActivatedWindowExplorerEvent(hWinEventHook, event, hWnd, *) => (Critical(-1), SetVlcVideoOutputForRelevantFeatureFix(hWnd))
  207. HandleSelectionExplorerEvent(hWinEventHook, event, hWnd, *) => (Critical(-1), SetVlcVideoOutputForRelevantFeatureFix(hWnd))
  208.  
  209.  
  210.  
  211.  
  212.  
  213. >>>I think it's like this ("New AutoHotkey Script.ahk" & "New AutoHotkey Script - Copy.ahk" shows the following behaviour when critical is used in all WinEvent handlers):
  214. Critical(-1) in WinEvent handler will make any non-WinEvent-handler thread unable to overtake, doesn't matter if there are windowing delays, sleep or Wait functions. instead they will get
  215. buffered until the WinEvent handler finishes completely. but other WinEvent handlers can overtake it immediately, doesn't matter if there are windowing delays, sleep or Wait functions.
  216. however when the DllCall "Sleep" is used, then as long as that DllCall hasn't finished, it will buffer any WinEvent and any other event such as hotkeys and timers
  217.  
  218. could check "test - Copy - Copy.ahk" as well but the two new scripts seemed to indicate the complete behaviour clear enough
  219.  
  220. /********** TRASH: `test - Copy - Copy.ahk` (part of latest test files) **********/
  221.  
  222. #Requires AutoHotkey 2.0
  223. Persistent()
  224. A_CoordModeToolTip := "Screen"
  225.  
  226. EVENT_SYSTEM_FOREGROUND := 0x0003
  227. EVENT_OBJECT_SHOW := 0x8002
  228. text := ""
  229.  
  230. HookEvent(EVENT_SYSTEM_FOREGROUND, HandleActivatedWindowTaskbarEvent)
  231. HookEvent(EVENT_OBJECT_SHOW, HandleShowedFullscreenWinEvent)
  232. HookEvent(event, fnObj, pid := 0) => DllCall("SetWinEventHook", "UInt", event, "UInt", event, "Ptr", 0, "Ptr", CallbackCreate(fnObj), "UInt", pid, "UInt", 0, "UInt", 0)
  233.  
  234. ;there's also a WinAPI Sleep fn..
  235.  
  236. F1:: ; seems like hotkeys and timers can interrupt w/o critical and get buffered w/ critical (tested with Sleep only, but Sleep might be irrelevant b/c they might overtake at any line)
  237. tf(*) ; and I think WinEvent handlers can interrupt a thread whether it has or doesn't have critical, as long as it's sleeping (not sure if I actually ever tested it w/ critical tho)
  238. {
  239. global text .= " _____"
  240. Tooltip(text)
  241. }
  242. HandleActivatedWindowTaskbarEvent(hWinEventHook, event, hWnd, *)
  243. {
  244. static count := 0
  245.  
  246. try
  247. {
  248. Critical(-1) ; (W/ BUSY-WAIT) 1 1 2 2 3 3 when uncommented, 1 2 3 3 2 1 when commented-out
  249. ;SetTimer(tf, -1)
  250. global text .= " ^^f" (id := ++count)
  251. Tooltip(text)
  252. loop (8000000) ; Approx. 2sec busy-wait (has approx. 30% CPU usage at most)
  253. continue
  254. ;loop (4)
  255. ; Sleep(200) ;Sleep(-1) ; (W/ CRITICAL ON) 1 2 3 3 2 1 when uncommented, 1 1 2 2 3 3 when commented-out
  256. ;,
  257. Tooltip(text .= " ^^f" id)
  258. }
  259. }
  260.  
  261. HandleShowedFullscreenWinEvent(hWinEventHook, event, hWnd, *)
  262. {
  263. static count := 0
  264.  
  265. try
  266. {
  267. Critical(-1) ; (W/ BUSY-WAIT) 1 1 2 2 3 3 when uncommented, 1 2 3 3 2 1 when commented-out
  268. ;SetTimer(tf, -1)
  269. global text .= " __s" (id := ++count)
  270. Tooltip(text)
  271. loop (8000000) ; Approx. 2sec busy-wait (has approx. 30% CPU usage at most)
  272. continue
  273. ;loop (4)
  274. ; Sleep(200) ;Sleep(-1) ; (W/ CRITICAL ON) 1 2 3 3 2 1 when uncommented, 1 1 2 2 3 3 when commented-out
  275. ;,
  276. Tooltip(text .= " __s" id)
  277. }
  278. }
  279.  
  280. /********** TRASH: `New AutoHotkey Script.ahk` (part of latest test files) **********/
  281.  
  282. #Requires AutoHotkey 2.0
  283. A_WinDelay := -1 ; For the snip feature, HandleNameChangedThunderbirdEvent, HandleNameChangedTabsOutlinerEvent and the two different HandleCreatedVlcEvent functions
  284. A_KeyDelay := -1 ; For the XButton hotkeys (ControlSend) and for Send b/c it reverts to the Event SendMode when another AHK script installs a native low-level keyboard/mouse hook
  285. A_KeyDuration := 1 ; For the XButton hotkeys
  286. /* [..,..,.. Sleep workaround works no matter what, but WinEvent handler can overtake shortly before or immediately after the Sleep workaround is done in the other WinEvent handler]
  287. ;HookEvent(0x8000, _HandleCreatedVlcEvent) ; [DIFFERENT EVENT, SAME FN, YES]
  288. HookEvent(0x0003, __HandleCreatedVlcEvent) ; [SAME EVENT, DIFFERENT FN, YES]
  289. HookEvent(0x0003, _HandleCreatedVlcEvent) ; [SAME EVENT, DIFFERENT FN, YES] ; [DIFFERENT EVENT, SAME FN, YES] ; TESTING IF A FOREGROUND WINEVENT HANDLER CAN OVERTAKE THE CREATE WINEVENT....
  290. */
  291. HookEvent(0x8000, HandleCreatedVlcEvent)
  292. ;HookEvent(0x0003, __HandleCreatedVlcEvent)
  293. HookEvent(0x0003, _HandleCreatedVlcEvent) ; TESTING IF A FOREGROUND WINEVENT HANDLER CAN OVERTAKE THE CREATE WINEVENT HANDLER ABOVE (W/ & W/O CRITICAL)
  294. /* [..,..,.. LAST ONE I TESTED]
  295. HookEvent(0x8000, _HandleCreatedVlcEvent) ; [DIFFERENT EVENT, DIFFERENT FN, YES]
  296. ;HookEvent(0x0003, __HandleCreatedVlcEvent)
  297. HookEvent(0x0003, HandleCreatedVlcEvent) ; [DIFFERENT EVENT, DIFFERENT FN, YES] ; TESTING IF A FOREGROUND WINEVENT HANDLER CAN OVERTAKE THE CREATE WINEVENT HANDLER ABOVE (W/ & W/O CRITICAL)
  298. */
  299. loop
  300. Sleep(100)
  301.  
  302. /*F1::
  303. {
  304. Critical(-1)
  305. Sleep(5000)
  306. tooltip("k")
  307. }
  308. */F11::tooltip("hm")
  309.  
  310. txt := ""
  311. HandleCreatedVlcEvent(hWinEventHook, event, hWnd, *)
  312. {
  313. ;Critical(-1)
  314. static bool := false
  315.  
  316. try
  317. if (!bool && WinGetProcessName(hWnd) = "vlc.exe" && WinGetClass(hWnd) = "Qt5QWindowIcon" && WinGetTitle(hWnd) != "Building font cache")
  318. {
  319. bool := true
  320. global txt .= "start "
  321. tooltip("> " txt)
  322. Hotkey("F12", (*) => MsgBox("hi " (A_TickCount - start)), "On")
  323. SetTimer((*) => MsgBox("TIME " (A_TickCount - start)), -2000)
  324. global start := A_TickCount
  325.  
  326. while (A_TickCount - start < 7000)
  327. { ; / immediately on event
  328. ;continue ;Sleep(3510) ; both make hotkey and timer interrupt immediately w/o critical Timer, F11 & F12 get buffered until after `Done` is shown w/ critical,other WinEvent handler overtake
  329. DllCall("Sleep", "UInt", 6510) ; ...makes hotkey and timer get buffered w/o critical Timer, F11 & F12 get buffered until after `Done` is shown w/ critical,other WinEvent handler overtake
  330. } ; \ after DllCall
  331.  
  332. tooltip("done " (A_TickCount - start))
  333. Sleep(-1) ; Discards queued events that might remain
  334. DllCall("Sleep", "UInt", 3510)
  335. bool := false
  336. }
  337. }
  338. _HandleCreatedVlcEvent(hWinEventHook, event, hWnd, *)
  339. {
  340. Critical(-1)
  341. static bool := false
  342. static cnt := 0
  343. try
  344. if (!bool && WinGetProcessName(hWnd) = "vlc.exe" && WinGetClass(hWnd) = "Qt5QWindowIcon" && WinGetTitle(hWnd) != "Building font cache")
  345. {
  346. ; bool := true
  347. /*global txt .= "_start "
  348. tooltip(txt)
  349. start := A_TickCount
  350. if (++cnt = 1)
  351. while (A_TickCount - start < 7000)
  352. {
  353. ;continue ;Sleep(26510) ;continue ;Sleep(3510) ; both make hotkey and timer interrupt immediately w/o critical Timer, F11 & F12 get buffered until after `Done` is shown w/ critical
  354. ;DllCall("Sleep", "UInt", 26510) ; ...makes hotkey and timer get buffered w/o critical Timer, F11 & F12 get buffered until after `Done` is shown w/ critical
  355. }
  356. */
  357. tooltip("_done " txt)
  358. ; LEAVE BOOL TRUE B/C VLC WILL OTHERWISE RETRIGGER FOREGROUND EVENT WHEN MSGBOX GETS CLOSED
  359. }
  360. }
  361. __HandleCreatedVlcEvent(hWinEventHook, event, hWnd, *)
  362. {
  363. Critical(-1)
  364. static bool := false
  365. static cnt := 0
  366. try
  367. if (!bool && WinGetProcessName(hWnd) = "vlc.exe" && WinGetClass(hWnd) = "Qt5QWindowIcon" && WinGetTitle(hWnd) != "Building font cache")
  368. {
  369. ; bool := true
  370. tooltip("_DONE " txt)
  371. ; LEAVE BOOL TRUE B/C VLC WILL OTHERWISE RETRIGGER FOREGROUND EVENT WHEN MSGBOX GETS CLOSED
  372. }
  373. }
  374.  
  375. HookEvent(event, fnObj, pid := 0) => DllCall("SetWinEventHook", "UInt", event, "UInt", event, "Ptr", 0, "Ptr", CallbackCreate(fnObj), "UInt", pid, "UInt", 0, "UInt", 0)
  376.  
  377. /********** TRASH: `New AutoHotkey Script - Copy.ahk` (part of latest test files) **********/
  378.  
  379. #Requires AutoHotkey 2.0
  380. A_WinDelay := -1 ; For the snip feature, HandleNameChangedThunderbirdEvent, HandleNameChangedTabsOutlinerEvent and the two different HandleCreatedVlcEvent functions
  381. A_KeyDelay := -1 ; For the XButton hotkeys (ControlSend) and for Send b/c it reverts to the Event SendMode when another AHK script installs a native low-level keyboard/mouse hook
  382. A_KeyDuration := 1 ; For the XButton hotkeys
  383. HookEvent(0x8000, HandleCreatedVlcEvent) ; TESTING THIS ONE ALONE WITH HOTKEY & TIMER, BUT COMMENT-OUT THE HOTKEY & TIMER WHEN TESTING THE WINEVENT HANDLER BELOW OVERTAKING THIS ONE <----
  384. ;HookEvent(0x0003, _HandleCreatedVlcEvent) ; TESTING IF A FOREGROUND WINEVENT HANDLER CAN OVERTAKE THE CREATE WINEVENT HANDLER ABOVE (W/ & W/O CRITICAL)
  385. ;Critical(-1) ; disabled early or not, doesn't matter.. WinEvent handlers still overtake eachother
  386. loop
  387. Sleep(100)
  388.  
  389. F1::
  390. {
  391. Critical(-1)
  392. tooltip("F1")
  393. ;SetTimer((*) => MsgBox("TIME"), -2000)
  394. Sleep(10000)
  395. tooltip("k")
  396. }
  397. F11::tooltip("hm")
  398.  
  399. txt := ""
  400. HandleCreatedVlcEvent(hWinEventHook, event, hWnd, *)
  401. {
  402. Critical(-1)
  403. static bool := false
  404.  
  405. try
  406. if (!bool && WinGetProcessName(hWnd) = "vlc.exe" && WinGetClass(hWnd) = "Qt5QWindowIcon" && WinGetTitle(hWnd) != "Building font cache")
  407. {
  408. bool := true
  409. global txt .= "start "
  410. tooltip(txt)
  411. ;Hotkey("F12", (*) => MsgBox("hi"), "On")
  412. ;SetTimer((*) => MsgBox("TIME"), -2000)
  413. start := A_TickCount
  414.  
  415. while (A_TickCount - start < 7000)
  416. { ; / immediately on event
  417. ;continue ;Sleep(13510) ; both make hotkey and timer interrupt immediately w/o critical Timer, F11 & F12 get buffered until after `Done` is shown w/ critical,other WinEvent handler overtake
  418. DllCall("Sleep", "UInt", 13510) ; ...makes hotkey and timer get buffered w/o critical Timer, F11 & F12 get buffered until after `Done` is shown w/ critical,other WinEvent handler overtake
  419. } ; \ after DllCall
  420.  
  421. tooltip("done")
  422. Sleep(-1) ; Discards queued events that might remain
  423. DllCall("Sleep", "UInt", 3510)
  424. bool := false
  425. }
  426. }
  427. _HandleCreatedVlcEvent(hWinEventHook, event, hWnd, *)
  428. {
  429. Critical(-1)
  430. static bool := false
  431.  
  432. try
  433. if (!bool && WinGetProcessName(hWnd) = "vlc.exe" && WinGetClass(hWnd) = "Qt5QWindowIcon" && WinGetTitle(hWnd) != "Building font cache")
  434. {
  435. bool := true
  436. global txt .= "_start "
  437. tooltip(txt)
  438. start := A_TickCount
  439.  
  440. while (A_TickCount - start < 7000)
  441. {
  442. ;continue ;Sleep(3510) ; both make hotkey and timer interrupt immediately w/o critical Timer, F11 & F12 get buffered until after `Done` is shown w/ critical
  443. DllCall("Sleep", "UInt", 3510) ; ...makes hotkey and timer get buffered w/o critical Timer, F11 & F12 get buffered until after `Done` is shown w/ critical
  444. }
  445.  
  446. tooltip("_done")
  447. ; LEAVE BOOL TRUE B/C VLC WILL OTHERWISE RETRIGGER FOREGROUND EVENT WHEN MSGBOX GETS CLOSED
  448. }
  449. }
  450.  
  451. HookEvent(event, fnObj, pid := 0) => DllCall("SetWinEventHook", "UInt", event, "UInt", event, "Ptr", 0, "Ptr", CallbackCreate(fnObj), "UInt", pid, "UInt", 0, "UInt", 0)
  452.  
  453. /********** TRASH: `_test - Copy - Copy - Copy.ahk` (part of extra test files that are even newer) **********/
  454.  
  455. #Requires AutoHotkey 2.0
  456. Persistent()
  457. A_CoordModeToolTip := "Screen"
  458.  
  459. EVENT_SYSTEM_FOREGROUND := 0x0003
  460. EVENT_OBJECT_SHOW := 0x8002
  461. text := ""
  462.  
  463. HookEvent(EVENT_SYSTEM_FOREGROUND, HandleActivatedWindowTaskbarEvent)
  464. HookEvent(EVENT_OBJECT_SHOW, HandleShowedFullscreenWinEvent)
  465. HookEvent(event, fnObj, pid := 0) => DllCall("SetWinEventHook", "UInt", event, "UInt", event, "Ptr", 0, "Ptr", CallbackCreate(fnObj), "UInt", pid, "UInt", 0, "UInt", 0)
  466.  
  467. ;there's also a WinAPI Sleep fn..
  468.  
  469. F1:: ; seems like hotkeys and timers can interrupt w/o critical and get buffered w/ critical (tested with Sleep only, but Sleep might be irrelevant b/c they might overtake at any line)
  470. tf(*) ; and I think WinEvent handlers can interrupt a thread whether it has or doesn't have critical, as long as it's sleeping (not sure if I actually ever tested it w/ critical tho)
  471. {
  472. global text .= " _____"
  473. Tooltip(text)
  474. }
  475. HandleActivatedWindowTaskbarEvent(hWinEventHook, event, hWnd, *)
  476. {
  477. ;Critical(-1) ; Even without this, it finishes completely before the next goes (w/ busy-wait, plus w/ and w/o sleep)
  478. static count := 0
  479.  
  480. try
  481. {
  482. ; Critical(-1) ; (W/ BUSY-WAIT) 1 1 2 2 3 3 when uncommented, 1 2 3 3 2 1 when commented-out
  483. ;SetTimer(tf, -1)
  484. global text .= " ^^f" (id := ++count)
  485. Tooltip(text)
  486. start := A_TickCount
  487.  
  488. while (A_TickCount - start < 200) ;7000)
  489. ; loop (80000000) ; Approx. 2sec busy-wait (has approx. 30% CPU usage at most)
  490. continue
  491. ;loop (4)
  492. Sleep(7000) ;200) ;Sleep(-1) ; (W/ CRITICAL ON) 1 2 3 3 2 1 when uncommented, 1 1 2 2 3 3 when commented-out
  493. ;,
  494. Tooltip(text .= " ^^f" id)
  495. }
  496. }
  497.  
  498. HandleShowedFullscreenWinEvent(hWinEventHook, event, hWnd, *)
  499. {
  500. ;Critical(-1)
  501. static count := 0
  502.  
  503. try
  504. {
  505. ; Critical(-1) ; (W/ BUSY-WAIT) 1 1 2 2 3 3 when uncommented, 1 2 3 3 2 1 when commented-out
  506. ;SetTimer(tf, -1)
  507. global text .= " __s" (id := ++count)
  508. Tooltip(text)
  509. loop (800000000) ; Approx. 2sec busy-wait (has approx. 30% CPU usage at most)
  510. continue
  511. ;loop (4)
  512. Sleep(200) ;Sleep(-1) ; (W/ CRITICAL ON) 1 2 3 3 2 1 when uncommented, 1 1 2 2 3 3 when commented-out
  513. ;,
  514. Tooltip(text .= " __s" id)
  515. }
  516. }
  517.  
  518. /********** TRASH: `_test - Copy - Copy - Copy - Copy.ahk` (part of extra test files that are even newer) **********/
  519.  
  520. #Requires AutoHotkey 2.0
  521. Persistent()
  522. A_CoordModeToolTip := "Screen"
  523.  
  524. EVENT_SYSTEM_FOREGROUND := 0x0003
  525. EVENT_OBJECT_SHOW := 0x8002
  526. text := ""
  527.  
  528. HookEvent(EVENT_SYSTEM_FOREGROUND, HandleActivatedWindowTaskbarEvent)
  529. HookEvent(EVENT_OBJECT_SHOW, HandleShowedFullscreenWinEvent)
  530. HookEvent(event, fnObj, pid := 0) => DllCall("SetWinEventHook", "UInt", event, "UInt", event, "Ptr", 0, "Ptr", CallbackCreate(fnObj), "UInt", pid, "UInt", 0, "UInt", 0)
  531.  
  532. ;there's also a WinAPI Sleep fn..
  533.  
  534. F1:: ; seems like hotkeys and timers can interrupt w/o critical and get buffered w/ critical (tested with Sleep only, but Sleep might be irrelevant b/c they might overtake at any line)
  535. tf(*) ; and I think WinEvent handlers can interrupt a thread whether it has or doesn't have critical, as long as it's sleeping (not sure if I actually ever tested it w/ critical tho)
  536. {
  537. global text .= " _____"
  538. Tooltip(text)
  539. }
  540. HandleActivatedWindowTaskbarEvent(hWinEventHook, event, hWnd, *)
  541. {
  542. Critical(-1)
  543. static bool := false
  544.  
  545. try
  546. if (!bool && WinGetProcessName(hWnd) = "vlc.exe" && WinGetClass(hWnd) = "Qt5QWindowIcon" && WinGetTitle(hWnd) != "Building font cache")
  547. {
  548. bool := true
  549. global text .= " ^^f" (id := ++count)
  550. Tooltip(text)
  551. start := A_TickCount
  552.  
  553. ;while (A_TickCount - start < 7000)
  554. loop (80000000) ; Approx. 2sec busy-wait (has approx. 30% CPU usage at most)
  555. continue
  556. ;loop (4)
  557. Sleep(200) ;Sleep(-1) ; (W/ CRITICAL ON) 1 2 3 3 2 1 when uncommented, 1 1 2 2 3 3 when commented-out
  558. ;,
  559. Tooltip(text .= " ^^f" id)
  560. bool := false
  561. }
  562. }
  563.  
  564. HandleShowedFullscreenWinEvent(hWinEventHook, event, hWnd, *)
  565. {
  566. Critical(-1)
  567. static bool := false
  568.  
  569. try
  570. if (!bool && WinGetProcessName(hWnd) = "vlc.exe" && WinGetClass(hWnd) = "Qt5QWindowIcon" && WinGetTitle(hWnd) != "Building font cache")
  571. {
  572. bool := true
  573. ;msgbox("?")
  574. global text .= " ^^f" (id := ++count)
  575. Tooltip(text)
  576. start := A_TickCount
  577.  
  578. ;while (A_TickCount - start < 7000)
  579. loop (80000000) ; Approx. 2sec busy-wait (has approx. 30% CPU usage at most)
  580. continue
  581. ;loop (4)
  582. Sleep(200) ;Sleep(-1) ; (W/ CRITICAL ON) 1 2 3 3 2 1 when uncommented, 1 1 2 2 3 3 when commented-out
  583. ;,
  584. Tooltip(text .= " ^^f" id)
  585. bool := false
  586. }
  587. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement