MattHiggs Posted December 5, 2023 Posted December 5, 2023 Hello all. So I am having a bit of an issue. Consider the below script: expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <AutoItConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <Constants.au3> #include <UpDownConstants.au3> Global $Form1 = GUICreate("Form1", 530, 280, 192, 124, BitOR($GUI_SS_DEFAULT_GUI, $DS_SETFOREGROUND), BitOR($WS_EX_TOPMOST, $WS_EX_WINDOWEDGE)) $MenuItem1 = GUICtrlCreateMenu("Actions") $MenuItem2 = GUICtrlCreateMenuItem("Auto urls", $MenuItem1) $Label1 = GUICtrlCreateLabel("Title page", 194, 8, 90, 29) GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif") $Input1 = GUICtrlCreateInput("", 16, 40, 449, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_NOHIDESEL)) $Button10 = GUICtrlCreateButton("Paste", 470, 30, 55, 40, $BS_NOTIFY) $Label2 = GUICtrlCreateLabel("Some input", 167, 72, 144, 29) GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif") $input2 = GUICtrlCreateInput("", 16, 104, 449, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_NOHIDESEL)) $button11 = GUICtrlCreateButton("Paste", 470, 94, 55, 40, $BS_NOTIFY) $Button5 = GUICtrlCreateButton("<", 20, 144, 105, 41, $BS_NOTIFY) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") GUICtrlSetCursor(-1, 0) $Button6 = GUICtrlCreateButton(">", 350, 144, 105, 41, $BS_NOTIFY) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") GUICtrlSetCursor(-1, 0) $Button7 = GUICtrlCreateButton("Close", 184, 144, 105, 41, $BS_NOTIFY) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") GUICtrlSetCursor(-1, 0) $Button1 = GUICtrlCreateButton("Download", 184, 210, 105, 41, $BS_NOTIFY) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlSetCursor(-1, 0) $button12 = GUICtrlCreateButton ( "Button12", 465, 170, 50, 50, $BS_NOTIFY ) GUICtrlSetCursor(-1, 0) $button8 = GUICtrlCreateButton("move tab left", 20, 210, 105, 41, $BS_NOTIFY) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") GUICtrlSetCursor(-1, 0) $Input3 = GUICtrlCreateInput("1", 135, 220, 40, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_RIGHT, $ES_NUMBER)) $Updown1 = GUICtrlCreateUpdown($Input3, BitOR($UDS_ALIGNRIGHT, $UDS_ARROWKEYS, $UDS_NOTHOUSANDS)) GUICtrlSetLimit(-1, 100, 1) $Input4 = GUICtrlCreateInput("1", 297, 220, 40, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_RIGHT, $ES_NUMBER)) $Updown2 = GUICtrlCreateUpdown($Input4, BitOR($UDS_ALIGNRIGHT, $UDS_ARROWKEYS, $UDS_NOTHOUSANDS)) GUICtrlSetLimit(-1, 100, 1) $button9 = GUICtrlCreateButton("move tab right", 350, 210, 105, 41, $BS_NOTIFY) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") GUICtrlSetCursor(-1, 0) GUISetState(@SW_SHOW) $cur = ClipGet () While True $new = ClipGet () If $cur <> $new Then MsgBox ( 1, "", "cur:" & @CRLF & $cur & @CRLF & "new:" & @CRLF & $new & @CRLF & "End" ) ; more code down here to run if clipboard change detected $cur = $new EndIf $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd The GUI here is irrelevant. What I am trying to do is have this script monitor the host's clipboard in the background, and perform certain actions when a change in the clipboard is detected, so the relevant code here would be: $cur = ClipGet () While True $new = ClipGet () If $cur <> $new Then MsgBox ( 1, "", "cur:" & @CRLF & $cur & @CRLF & "new:" & @CRLF & $new & @CRLF & "End" ) ; more code down here to run if clipboard change detected $cur = $new EndIf $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Right now, when the script detects a clipboard change, it shows a message box displaying what the script had stored as the previous clipboard contents and the current contents for debugging purposes, as I have been having an issue where this code is constantly being executed even when there have been no changes made to the clipboard. What I found is that clipget() is intermittently....well...I don't know if the function is failing or just returning a null value/empty string when it shouldn't, as the script will just alternate these two message boxes when left to run: And Can anyone help me figure out how I can fix this? Or maybe I am just going about the clipboard change detection all wrong? Any suggestions would be great
argumentum Posted December 5, 2023 Posted December 5, 2023 ClipGet() Retrieves text from the clipboard. Return Value Success: a string containing the text on the clipboard. Failure: sets the @error to non-zero. @error: 1 = if clipboard is empty 2 = if contains a non-text entry. 3 or 4 = if cannot access the clipboard. Have you tried error checking ? Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
paw Posted December 6, 2023 Posted December 6, 2023 You want to use this https://www.autoitscript.com/autoit3/docs/libfunctions/_WinAPI_AddClipboardFormatListener.htm
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now