Skip to content

Commit a9f36a5

Browse files
authored
Refactor DownloadDemo.au3 to improve structure
1 parent d24323b commit a9f36a5

1 file changed

Lines changed: 0 additions & 66 deletions

File tree

examples/006-DownloadDemo.au3

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -148,69 +148,3 @@ Volatile Func __UserEventHandler__OnAcceleratorKeyPressed($oWebV2M, $hGUI, $oArg
148148

149149
$oArgs = 0 ; Explicitly release the COM reference inside the volatile scope
150150
EndFunc ;==>__UserEventHandler__OnAcceleratorKeyPressed
151-
152-
; Advise using 'Volatile' for Event Handlers to ensure the WebView2 COM thread can interrupt the main script safely.
153-
Volatile Func __UserEventHandler__OnAcceleratorKeyPressed00($oWebV2M, $hGUI, $oArgs)
154-
Local Const $sArgsList = '[VirtualKey=' & $oArgs.VirtualKey & _ ; The VK code of the key.
155-
'; KeyEventKind=' & $oArgs.KeyEventKind & _ ; Type of key event (Down, Up, etc.).
156-
'; Handled=' & $oArgs.Handled & _ ; Set to `True` to stop the browser from processing the key.
157-
'; RepeatCount=' & $oArgs.RepeatCount & _ ; The number of times the key has repeated.
158-
'; ScanCode=' & $oArgs.ScanCode & _ ; Hardware scan code.
159-
'; IsExtendedKey=' & $oArgs.IsExtendedKey & _ ; True if it's an extended key (e.g., right Alt).
160-
'; IsMenuKeyDown=' & $oArgs.IsMenuKeyDown & _ ; True if Alt is pressed.
161-
'; WasKeyDown=' & $oArgs.WasKeyDown & _ ; True if the key was already down.
162-
'; IsKeyReleased=' & $oArgs.IsKeyReleased & _ ; True if the event is a key up.
163-
'; KeyEventLParam=' & $oArgs.KeyEventLParam & ']' ; Gets the LPARAM value that accompanied the window message.
164-
165-
166-
Local Const $s_Prefix = "[USER:EVENT: OnAcceleratorKeyPressed]:: GUI:" & $hGUI & " ARGS: " & ((IsObj($oArgs)) ? ($sArgsList) : ('ERRROR'))
167-
168-
;~ public uint VirtualKey { get; }
169-
;~ public int KeyEventLParam { get; }
170-
;~ public int KeyEventKind { get; }
171-
;~
172-
;~ public uint RepeatCount { get; }
173-
;~ public uint ScanCode { get; }
174-
;~ public bool IsExtendedKey { get; }
175-
;~ public bool IsMenuKeyDown { get; }
176-
;~ public bool WasKeyDown { get; }
177-
;~ public bool IsKeyReleased { get; }
178-
179-
;~ https://learn.microsoft.com/en-us/dotnet/api/microsoft.web.webview2.core.corewebview2acceleratorkeypressedeventargs?view=webview2-dotnet-1.0.705.50
180-
;~ ConsoleWrite($oArgs.Handled & @CRLF) ; Indicates whether the AcceleratorKeyPressed event is handled by host.
181-
;~ ConsoleWrite($oArgs.KeyEventKind & @CRLF) ; Gets the key event kind that caused the event to run
182-
;~ ConsoleWrite($oArgs.KeyEventLParam & @CRLF) ; Gets the LPARAM value that accompanied the window message.
183-
;~ ConsoleWrite('>> PhysicalKeyStatus=' & $oArgs.PhysicalKeyStatus & @CRLF) ; Gets a CoreWebView2PhysicalKeyStatus representing the information passed in the LPARAM of the window message. ==> ; https://learn.microsoft.com/en-us/dotnet/api/microsoft.web.webview2.core.corewebview2physicalkeystatus?view=webview2-dotnet-1.0.705.50
184-
;~ ConsoleWrite($oArgs.VirtualKey & @CRLF) ; Gets the Win32 virtual key code of the key that was pressed or released.
185-
186-
;~ If $oArgs.VirtualKey = 27 Then ; ESC 27 1b 033 Escape, next character is not echoed ; https://www.autoitscript.com/autoit3/docs/appendix/ascii.htm
187-
;~ $oWebV2M.CancelDownloads($_sURLDownload_InProgress)
188-
;~ EndIf
189-
190-
; Example of checking specific keys
191-
Switch $oArgs.VirtualKey
192-
Case Int($VK_F7)
193-
ConsoleWrite("! Blocked: F7 caret browsing." & @CRLF)
194-
$oArgs.Handled = True
195-
196-
Case Int($VK_N)
197-
; Check if Ctrl is pressed (using IsMenuKeyDown if it concerns Alt or WinAPI for Ctrl)
198-
; If we want to block Ctrl+N (New Window)
199-
If _IsPressed("11") Then ; Need Misc.au3 for _IsPressed
200-
ConsoleWrite("! Blocked: Ctrl+N shortcut." & @CRLF)
201-
$oArgs.Handled = True
202-
203-
EndIf
204-
205-
Case Int($VK_ESCAPE) ; ESC 27 1b 033 Escape, next character is not echoed ; https://www.autoitscript.com/autoit3/docs/appendix/ascii.htm
206-
; Cancels active downloads. If `uri` is empty or omitted, cancels all active downloads.
207-
$oWebV2M.CancelDownloads()
208-
209-
EndSwitch
210-
211-
__NetWebView2_Log(@ScriptLineNumber, $s_Prefix, 0)
212-
$oArgs = 0 ; Explicitly release the COM reference inside the volatile scopeEndFunc
213-
214-
EndFunc ;==>__UserEventHandler__OnAcceleratorKeyPressed00
215-
216-

0 commit comments

Comments
 (0)