Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 11/28/2023 in all areas

  1. jaberwacky

    Me vs. ChatGPT

    At my work I use a program which requires all caps. My work is high paced and so switching back and forth all day between all caps is a pain. So I wrote a script that toggles caps lock on and off accordingly. What follows is my version (which may not work at that point) and then followed by ChatGPTs version. I have since modified ChatGPTs version to suit my particular quirky coding style. The biggest changes that ChatGPT made are to the MousePosition, WindowUnderMouse (originally written by Ascendant), and IsCDKActive functions. Sorry. Something funky is going on. I must not have access to the very original code I fed to ChatGPT ... Puny human version (but still pretty good if I do say so myself.): #include <APISysConstants.au3> #include <WinAPISysWin.au3> #include <WinAPI.au3> #include <Misc.au3> #include <GUIConstants.au3> Opt("SendCapslockMode", 0) Opt("WinTitleMatchMode", 2) Global Const $mouse_proc_callback = DllCallbackRegister(CapslockSentinel, "long", "int;wparam;lparam") Global Const $hook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($mouse_proc_callback), _WinAPI_GetModuleHandle(0)) OnAutoItExitRegister(OnAutoItExit) While True Sleep(1000) WEnd Func CapslockSentinel($code, $w_param, $l_param) Switch $code >= 0 Case True Switch $w_param Case $wm_mousemove Local Static $hWinPrev = ' ' Local Static $cdk_active = False Local Const $hWin = WindowUnderMouse($l_param) If $hWin <> $hWinPrev Then $hWinPrev = $hWin Local Const $title = WinGetTitle($hWin) Select Case IsCDKActive($title) And Not $cdk_active ConsoleWrite("CDK: Active -- Capslock: On" & @CRLF) If Not IsCapsLockOn() Then ToggleCapslock("On") EndIf $cdk_active = True Case Not IsCDKActive($title) And $cdk_active ConsoleWrite("CDK: Inactive -- Capslock: Off" & @CRLF) If IsCapsLockOn() Then ToggleCapslock("Off") EndIf $cdk_active = False EndSelect EndIf EndSwitch EndSwitch Return _WinAPI_CallNextHookEx($hook, $code, $w_param, $l_param) EndFunc Func MousePos(Const ByRef $l_Param) Local Const $MSLLHOOKSTRUCT = $tagPOINT & ";dword mouseData;dword flags;dword time;ulong_ptr dwExtraInfo" Local Const $info = DllStructCreate($MSLLHOOKSTRUCT, $l_Param) Local Const $mousePos[2] = [DllStructGetData($info, 1), DllStructGetData($info, 2)] Return $mousePos EndFunc Func WindowUnderMouse(Const ByRef $l_param) ; Ascendant Local Const $stPoint = DllStructCreate("long; long") Local Const $mousePos = MousePos($l_param) DllStructSetData($stPoint, 1, $mousePos[0]) DllStructSetData($stPoint, 2, $mousePos[1]) Local Const $stInt64 = DllStructCreate("int64", DllStructGetPtr($stPoint)) Local Const $aRet = DllCall("user32.dll", "hwnd", "WindowFromPoint", "int64", DllStructGetData($stInt64, 1))[0] ; Because _WindowFromPoint() can return 'sub' windows, or control handles, we should seek the owner window Return $aRet ? _WinAPI_GetAncestor($aRet, 2) : SetError(1, @error, 0) EndFunc Func IsCDKActive(Const ByRef $title) If StringInStr($title, "CDK Drive") Or _ StringInStr($title, "Tab Name") Or _ StringInStr($title, "Tab Color") Or _ StringInStr($title, "Create Order") Or _ StringInStr($title, "Cashiering") Or _ StringInStr($title, "Enter Change Reason") Then Return True EndIf Return False EndFunc Func IsCapsLockOn() Return BitAND(_WinAPI_GetKeyState(0x14), 0x01) = 1 EndFunc Func ToggleCapslock(Const ByRef $state) Send("{CAPSLOCK " & $state & '}') EndFunc Func OnAutoItExit() _WinAPI_UnhookWindowsHookEx($hook) DllCallbackFree($mouse_proc_callback) EndFunc ChatGPT: #include <APISysConstants.au3> #include <WinAPISysWin.au3> #include <WinAPI.au3> #include <Misc.au3> #include <GUIConstants.au3> Opt("SendCapslockMode", 0) Opt("WinTitleMatchMode", 2) Global Const $MOUSE_PROC_CALLBACK = DllCallbackRegister("CapslockSentinel", "long", "int;wparam;lparam") Global Const $HOOK = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($MOUSE_PROC_CALLBACK), _WinAPI_GetModuleHandle(0)) OnAutoItExitRegister("OnAutoItExit") While True Sleep(1000) WEnd Func CapslockSentinel($nCode, $wParam, $lParam) Switch $nCode >= 0 Case True Switch $wParam Case $WM_MOUSEMOVE Local Static $hPrevWin = ' ' Local Static $bCDKActive = False Local Const $hWin = GetWindowUnderMouse($lParam) If $hWin <> $hPrevWin Then $hPrevWin = $hWin Local Const $sTitle = WinGetTitle($hWin) If IsCDKActive($sTitle) And Not $bCDKActive Then ConsoleWrite("CDK: Active -- Capslock: On" & @CRLF) If Not IsCapsLockOn() Then ToggleCapsLock("On") $bCDKActive = True ElseIf Not IsCDKActive($sTitle) And $bCDKActive Then ConsoleWrite("CDK: Inactive -- Capslock: Off" & @CRLF) If IsCapsLockOn() Then ToggleCapsLock("Off") $bCDKActive = False EndIf EndIf EndSwitch EndSwitch Return _WinAPI_CallNextHookEx($HOOK, $nCode, $wParam, $lParam) EndFunc Func GetMousePos(Const ByRef $lParam) Local Const $MSLLHOOKSTRUCT = $tagPOINT & ";dword mouseData;dword flags;dword time;ulong_ptr dwExtraInfo" Local Const $info = DllStructCreate($MSLLHOOKSTRUCT, $lParam) Return DllStructCreate("int[2]", DllStructGetPtr($info)) EndFunc Func GetWindowUnderMouse(Const ByRef $lParam) Local Const $stPoint = GetMousePos($lParam) Local Const $stInt64 = DllStructCreate("int64", DllStructGetPtr($stPoint)) Local Const $hWnd = DllCall("user32.dll", "hwnd", "WindowFromPoint", "int64", DllStructGetData($stInt64, 1))[0] Return $hWnd ? _WinAPI_GetAncestor($hWnd, 2) : SetError(1, @error, 0) EndFunc Func IsCDKActive(Const ByRef $sTitle) Local Const $aKeywords = ["CDK Drive", "Tab Name", "Tab Color", "Create Order", "Cashiering", "Enter Change Reason"] For $i = 0 To UBound($aKeywords) - 1 If StringInStr($sTitle, $aKeywords[$i]) Then Return True Next Return False EndFunc Func IsCapsLockOn() Return BitAND(_WinAPI_GetKeyState(0x14), 0x01) = 1 EndFunc Func ToggleCapsLock(Const ByRef $sState) Send("{CAPSLOCK " & $sState & '}') EndFunc Func OnAutoItExit() _WinAPI_UnhookWindowsHookEx($HOOK) DllCallbackFree($MOUSE_PROC_CALLBACK) EndFunc
    2 points
  2. The GUI looks like shown in the picture: It contains a main menu, a treeview in left pane that lists UI Automation elements, a listview in right pane that displays detail information for the selected element, and a splitterbar to adjust the width of the two panes. Detect element The "Detect element" main menu is used to detect elements under the mouse with function keys F1 - F4. See How to topics number 2. Left pane The left pane is a treeview that initially lists open programs and windows. Generally, the left pane shows UI Automation elements represented as treeview items. Right pane The right pane is a listview that displays detail information for the selected treeview element. The information is grouped into different types of information. Only the relevant information for each type is displayed. Invalid elements When a window is closed the elements in UIASpy becomes invalid. But the elements are not deleted in UIASpy and can still be handled and selected in the treeview. Detail information for an element that was calculated before the window was closed can still be seen in the listview. In this way it's possible for UIASpy to show information for eg. a context menu that is closed as soon as it loses focus. Listview features Listview features Help system With completion of the Help system, a lot of information has been moved from this post and other posts into the Help system. Sample code creation Sample code creation is implemented through the UI element Detail info listview page and through the Sample code main menu. Sample code creates code snippets based on data in one or more selected rows in the Detail info listview page or based on the clicked Sample code menu item. UI Automation code is largely based on COM interface objects and thus on the function ObjCreateInterface(), which is one of the advanced functions in AutoIt. The main purpose of Sample code functionality is to eliminate the complexity of ObjCreateInterface(). Sample code creation either through the Detail info listview page or through the Sample code main menu can create all the interface objects required in UI Automation code. Another purpose is of course to make it easier and faster to implement code for simple automation tasks. Through Sample code creation, you can more or less create all code in a simple automation task: Create UI Automation initial code Create condition and find application window Create condition and find control in window Get information about windows and controls Create pattern objects to perform actions Get information related to pattern objects Perform actions with pattern object methods Add a Sleep() statement if necessary Note that the UI element used in sample code is named after the selected element in the treeview. Also note that both the Sample code menu items and the sections in the Detail info listview page are placed in approximately the order they are used in a simple automation task. Sample code creation through Detail info listview page Sample code creation through Sample code main menu Supported applications Most browsers including Google Chrome To be able to spy on web content in Google Chrome it's necessary to enable accessibility by entering chrome://accessibility/ in the address bar of a new tab item, and then check the five check boxes that are located in a column in upper left corner down along the left edge. Then the accessibility tab can be closed again. It's a global setting that applies to all open and new tabs until Chrome is closed. Without accessibility enabled you are only able to investigate the outer elements of Chrome but not web content. Internet Explorer Microsoft Edge Mozilla Firefox Most Microsoft applications and applications developed with Microsoft software including Classic Windows applications based on the standard control library Modern Universal Windows Platform apps like the Windows 10 Calculator Programs implemented through .NET Framework eg. Windows Forms applications Most applications provided by major development companies Automation issues Automation issues How to topics If UI Automation or the UIASpy tool is new to you, then you should read the How to topics. Examples Examples that demonstrates the features of UIASpy: Automating Notepad. Very detailed example. Automating Notepad - Windows XP Examples about Sample code creation: Automating Notepad with Sample code - step by step Automating Notepad with Sample code - all at once Chrome - Clicking an extension. Compact summary example. Click Save As... issue in Notepad examples: Using Expand() instead of Invoke() Updates Windows 8, Windows 8.1 and Windows 10 updates Threads UI Automation UDFs contains all include files. In Using UI Automation Code in AutoIt you can find and download examples and read information about using UIA code. UI Automation Events is about implementing event handlers and includes GUIs to detect events. IUIAutomation MS framework automate chrome, FF, IE, .... created by junkew August 2013 is the first AutoIt thread on UIA code. Zip-file The zip contains source files for UIASpy GUI. Note that UI Automation UDFs must be installed in the Includes folder. You need AutoIt 3.3.12 or later. Tested on Windows XP, Windows 7 and Windows 10. Comments are welcome. Let me know if there are any issues. UIASpy.7z
    1 point
  3. ntdll.dll has numerous functions to convert (u)int to string (and vice versa) . Example : DllCall("ntdll.dll", "str:cdecl", "_ui64toa", "uint64", $integer, "str", "", "int", $base) by using a $base = 2, you get a binary string of the $integer
    1 point
  4. I implemented fullscreen function with winmm.dll in my zPlayer and the following is a replication of that function. #include <GUIConstants.au3> HotKeySet("{F11}", "_FullScreen") Global $videoWidth = @DesktopWidth/3*2, $videoHeight = $videoWidth*9/16, $iGui, $iFullScreen $hVideoGUI = GUICreate("WINMM.DLL", $videoWidth, $videoHeight) $iGui = Dec(StringMid($hVideoGUI, 3)) GUISetState(@SW_HIDE, $hVideoGUI) $aPos = WinGetPos($hVideoGUI) $borderWidth = ($aPos[2]-$videoWidth)/2 $titleHeight = $aPos[3]-$videoHeight-$borderWidth GUISetState() $sFile = "D:\Video\Voorbeeld.mp4" GUIRegisterMsg($WM_MOVE, "WM_MOVE") $hDLL = DllOpen("winmm.dll") mciSendString("open """ & $sFile & """ alias myMedia type MPEGVideo style popup parent " & $iGui) $hVideo = WinGetHandle($sFile) WinMove($hVideo, "", $aPos[0]+$borderWidth, $aPos[1]+$titleHeight, $videoWidth, $videoHeight) mciSendString("play myMedia") While 1 Switch GUIGetMsg(0) Case $GUI_EVENT_CLOSE mciSendString("close myMedia") DllClose($hDLL) Exit EndSwitch If mciSendString("status myMedia mode") = "stopped" Then mciSendString("play myMedia from 0") EndIf WEnd Func mciSendString($string) Local $aRet = DllCall($hDLL, "int", "mciSendStringW", "wstr", $string, "wstr", "", "int", 65534, "hwnd", 0) If Not @error Then Return $aRet[2] EndFunc ;==>mciSendString Func _FullScreen() If WinGetState($hVideo) < 7 Then Return WinActivate($hVideoGUI) If $iFullScreen = 0 Then $aPos = WinGetPos($hVideoGUI) $iFullScreen = 1 WinMove($hVideo, "", 0, 0, @DesktopWidth, @DesktopHeight) Else $iFullScreen = 0 WinMove($hVideo, "", $aPos[0]+$borderWidth, $aPos[1]+$titleHeight, $videoWidth, $videoHeight) EndIf EndFunc Func WM_MOVE($hWnd, $MsgID, $wParam, $lParam) #forceref $hWnd, $MsgID, $wParam, $lParam If $hWnd <> $hVideoGUI Then Return $GUI_RUNDEFMSG If $iFullScreen = 1 Then Return $GUI_RUNDEFMSG $aPos = WinGetPos($hVideoGUI) Local $x1, $y1, $w1, $h1 $x1 = $aPos[0]+$borderWidth $y1 = $aPos[1]+$titleHeight $w1 = $aPos[2]-$borderWidth*2 $h1 = $aPos[3]-$titleHeight-$borderWidth WinMove($hVideo, "", $x1, $y1, $w1, $h1) Return $GUI_RUNDEFMSG EndFunc
    1 point
×
×
  • Create New...