Jump to content

[Solved] How can do clipboard listening inside while loop >Switch GUIGetMsg()?


Kyan
 Share

Recommended Posts

Hi everyone :oops:

does someone know, how can I execute a clipboard listening inside a while loop/Switch GUIGetMsg()?

I want to paste a url when the website domain matches with the one I want and paste this url in a input >this part I know how to do it, the problem is, how can I do it inside the main while loop (I want to be able to receive GUI commands and read the clipboard data...)

let me know if that is possible, and if it is, please give a tip :bye:

thanks

Edited by DiOgO

Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Link to comment
Share on other sites

  • Moderators

DiOgO,

Use ClipGet in the loop? Or perhaps use it in an Adlib function to reduce the overhead? :oops:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

DiOgO,

Use ClipGet in the loop? Or perhaps use it in an Adlib function to reduce the overhead? :oops:

M23

but the script will be listening the GUIGetMsg outputs, wouldn't be? inside the while loop/switch GUIGetMsg()? can it just be placed between switch tags?

Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Link to comment
Share on other sites

in this way, nothing happens :s

$Form1 = GUICreate("test", 370, 200,-1,-1)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg(1)
Switch $nMsg[1]
  Case $Form1
   Switch $nMsg[0]
    If (ClipGet() <> "") And (@error <> 2) Then
      If StringInStr(ClipGet(),"www.autoitscript.com") <> 0 Then
      MsgBox(0,"","URL")
      Sleep(5000)
     EndIf
    EndIf
    Case $GUI_EVENT_CLOSE
     Exit
   EndSwitch
EndSwitch
WEnd

Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Link to comment
Share on other sites

Use this :

GUIRegisterMsg($WM_CHANGECBCHAIN, "WM_CHANGECBCHAIN")

GUIRegisterMsg($WM_DRAWCLIPBOARD, "WM_DRAWCLIPBOARD")

There is example in the examples section for _ClipBoard_SetViewer

can you give a example of how can I use that commands?

Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Link to comment
Share on other sites

Use this :

GUIRegisterMsg($WM_CHANGECBCHAIN, "WM_CHANGECBCHAIN")

GUIRegisterMsg($WM_DRAWCLIPBOARD, "WM_DRAWCLIPBOARD")

There is example in the examples section for _ClipBoard_SetViewer

Teamspeak 3 User Viewer - Quick and functional TS3 Query script, which shows online users.Cached Screenshot Deleter - Deletes older Fraps Screenshots if they exceed a specified limit.Unresolved Topics:Intercept and modify dragdrop text behaviour in scite
Link to comment
Share on other sites

Copy from the examples:

#include <GuiConstantsEx.au3>
#include <ClipBoard.au3>
#include <WindowsConstants.au3>
#include <SendMessage.au3>

Opt('MustDeclareVars', 1)

Global $iMemo, $hNext = 0

_Main()

Func _Main()
    Local $hGUI

    ; Create GUI
    $hGUI = GUICreate("Clipboard", 600, 400)
    $iMemo = GUICtrlCreateEdit("", 2, 2, 596, 396, $WS_VSCROLL)
    GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")
    GUISetState()

    ; Initialize clipboard viewer
    $hNext = _ClipBoard_SetViewer ($hGUI)

    GUIRegisterMsg($WM_CHANGECBCHAIN, "WM_CHANGECBCHAIN")
    GUIRegisterMsg($WM_DRAWCLIPBOARD, "WM_DRAWCLIPBOARD")
    
    MemoWrite("GUI handle ....: " & $hGUI)
    MemoWrite("Viewer handle .: " & _ClipBoard_GetViewer())

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    ; Shut down clipboard viewer
    _ClipBoard_ChangeChain ($hGUI, $hNext)
EndFunc   ;==>_Main

; Write message to memo
Func MemoWrite($sMessage = "")
    GUICtrlSetData($iMemo, $sMessage & @CRLF, 1)
EndFunc   ;==>MemoWrite

; Handle $WM_CHANGECBCHAIN messages
Func WM_CHANGECBCHAIN($hWnd, $iMsg, $iwParam, $ilParam)
    ; Show that message was received
    MemoWrite("***** $WM_CHANGECBCHAIN *****")

    ; If the next window is closing, repair the chain
    If $iwParam = $hNext Then
        $hNext = $ilParam
        ; Otherwise pass the message to the next viewer
    ElseIf $hNext <> 0 Then
        _SendMessage ($hNext, $WM_CHANGECBCHAIN, $iwParam, $ilParam, 0, "hwnd", "hwnd")
    EndIf
EndFunc   ;==>WM_CHANGECBCHAIN

; Handle $WM_DRAWCLIPBOARD messages
Func WM_DRAWCLIPBOARD($hWnd, $iMsg, $iwParam, $ilParam)
    ; Display any text on clipboard
    MemoWrite(_ClipBoard_GetData ())

    ; Pass the message to the next viewer
    If $hNext <> 0 Then _SendMessage ($hNext, $WM_DRAWCLIPBOARD, $iwParam, $ilParam)
EndFunc   ;==>WM_DRAWCLIPBOARD
Link to comment
Share on other sites

sorry for that, I didn't read the final part :oops:

Copy from the examples:

#include <GuiConstantsEx.au3>
#include <ClipBoard.au3>
#include <WindowsConstants.au3>
#include <SendMessage.au3>

Opt('MustDeclareVars', 1)

Global $iMemo, $hNext = 0

_Main()

Func _Main()
    Local $hGUI

    ; Create GUI
    $hGUI = GUICreate("Clipboard", 600, 400)
    $iMemo = GUICtrlCreateEdit("", 2, 2, 596, 396, $WS_VSCROLL)
    GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")
    GUISetState()

    ; Initialize clipboard viewer
    $hNext = _ClipBoard_SetViewer ($hGUI)

    GUIRegisterMsg($WM_CHANGECBCHAIN, "WM_CHANGECBCHAIN")
    GUIRegisterMsg($WM_DRAWCLIPBOARD, "WM_DRAWCLIPBOARD")
    
    MemoWrite("GUI handle ....: " & $hGUI)
    MemoWrite("Viewer handle .: " & _ClipBoard_GetViewer())

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    ; Shut down clipboard viewer
    _ClipBoard_ChangeChain ($hGUI, $hNext)
EndFunc   ;==>_Main

; Write message to memo
Func MemoWrite($sMessage = "")
    GUICtrlSetData($iMemo, $sMessage & @CRLF, 1)
EndFunc   ;==>MemoWrite

; Handle $WM_CHANGECBCHAIN messages
Func WM_CHANGECBCHAIN($hWnd, $iMsg, $iwParam, $ilParam)
    ; Show that message was received
    MemoWrite("***** $WM_CHANGECBCHAIN *****")

    ; If the next window is closing, repair the chain
    If $iwParam = $hNext Then
        $hNext = $ilParam
        ; Otherwise pass the message to the next viewer
    ElseIf $hNext <> 0 Then
        _SendMessage ($hNext, $WM_CHANGECBCHAIN, $iwParam, $ilParam, 0, "hwnd", "hwnd")
    EndIf
EndFunc   ;==>WM_CHANGECBCHAIN

; Handle $WM_DRAWCLIPBOARD messages
Func WM_DRAWCLIPBOARD($hWnd, $iMsg, $iwParam, $ilParam)
    ; Display any text on clipboard
    MemoWrite(_ClipBoard_GetData ())

    ; Pass the message to the next viewer
    If $hNext <> 0 Then _SendMessage ($hNext, $WM_DRAWCLIPBOARD, $iwParam, $ilParam)
EndFunc   ;==>WM_DRAWCLIPBOARD

thank you :bye:

Alternatively, if you have Windows Vista+, you can use _WinAPI_AddClipboardFormatListener() from

thanks, but I prefer to have compatibility with windows XP :doh:

EDIT: how can I only write to my input only when the clip data is what I want?

using this way it pastes all the data (like this "if" doesn't exists)

If (StringInStr(_ClipBoard_GetViewer(),"www.autoitscript.com",0,1) <> 0) Then
     MemoWrite(_ClipBoard_GetViewer())
EndIf
Edited by DiOgO

Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Link to comment
Share on other sites

  • Moderators

DiOgO,

I told you what to do in the second post of this thread. :oops:

- 1. Use ClipGet in the loop:

#include <GUIConstantsEx.au3>
#include <EditConstants.au3>

$hGUI = GUICreate("Test", 500, 500)

$cInput = GUICtrlCreateInput("", 10, 10, 200, 20)

; Just to copy to check you get the correct response
GUICtrlCreateEdit("www.autoitscript.com" & @CRLF & "www.fred.com" & @CRLF & "www.tom.com" & @CRLF & "www.dick.com" & @CRLF & "www.harry.com", 10, 50, 200, 200, $ES_READONLY)

GUISetState()

$sClipContent = ""
ClipPut("")

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

    $sCurrContent = ClipGet()
    If $sCurrContent <> $sClipContent Then
        If $sCurrContent = "www.autoitscript.com" Then
            GUICtrlSetData($cInput, "That is the one!!!")
            ;ClipPut("")
        Else
            GUICtrlSetData($cInput, "Not what we wanted")
        EndIf
        $sClipContent = $sCurrContent
    EndIf

WEnd

- 2. Use it in an Adlib function to reduce the overhead:

#include <GUIConstantsEx.au3>
#include <EditConstants.au3>

$hGUI = GUICreate("Test", 500, 500)

$cInput = GUICtrlCreateInput("", 10, 10, 200, 20)

GUICtrlCreateEdit("www.autoitscript.com" & @CRLF & "www.fred.com" & @CRLF & "www.tom.com" & @CRLF & "www.dick.com" & @CRLF & "www.harry.com", 10, 50, 200, 200, $ES_READONLY)

GUISetState()

AdlibRegister("ClipCheck", 1000)

$sClipContent = ""
ClipPut("")

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

WEnd

Func ClipCheck()

    $sCurrContent = ClipGet()
    If $sCurrContent <> $sClipContent Then
        If $sCurrContent = "www.autoitscript.com" Then
            GUICtrlSetData($cInput, "That is the one!!!")
            ;ClipPut("")
        Else
            GUICtrlSetData($cInput, "Not what we wanted")
        EndIf
        $sClipContent = $sCurrContent
    EndIf

EndFunc

If you do want to use the Windows messages than you are forced to poll ClipGet somehow. :bye:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

DiOgO,

I told you what to do in the second post of this thread. :oops:

- 1. Use ClipGet in the loop:

#include <GUIConstantsEx.au3>
#include <EditConstants.au3>

$hGUI = GUICreate("Test", 500, 500)

$cInput = GUICtrlCreateInput("", 10, 10, 200, 20)

; Just to copy to check you get the correct response
GUICtrlCreateEdit("www.autoitscript.com" & @CRLF & "www.fred.com" & @CRLF & "www.tom.com" & @CRLF & "www.dick.com" & @CRLF & "www.harry.com", 10, 50, 200, 200, $ES_READONLY)

GUISetState()

$sClipContent = ""
ClipPut("")

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

    $sCurrContent = ClipGet()
    If $sCurrContent <> $sClipContent Then
        If $sCurrContent = "www.autoitscript.com" Then
            GUICtrlSetData($cInput, "That is the one!!!")
            ;ClipPut("")
        Else
            GUICtrlSetData($cInput, "Not what we wanted")
        EndIf
        $sClipContent = $sCurrContent
    EndIf

WEnd

- 2. Use it in an Adlib function to reduce the overhead:

#include <GUIConstantsEx.au3>
#include <EditConstants.au3>

$hGUI = GUICreate("Test", 500, 500)

$cInput = GUICtrlCreateInput("", 10, 10, 200, 20)

GUICtrlCreateEdit("www.autoitscript.com" & @CRLF & "www.fred.com" & @CRLF & "www.tom.com" & @CRLF & "www.dick.com" & @CRLF & "www.harry.com", 10, 50, 200, 200, $ES_READONLY)

GUISetState()

AdlibRegister("ClipCheck", 1000)

$sClipContent = ""
ClipPut("")

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

WEnd

Func ClipCheck()

    $sCurrContent = ClipGet()
    If $sCurrContent <> $sClipContent Then
        If $sCurrContent = "www.autoitscript.com" Then
            GUICtrlSetData($cInput, "That is the one!!!")
            ;ClipPut("")
        Else
            GUICtrlSetData($cInput, "Not what we wanted")
        EndIf
        $sClipContent = $sCurrContent
    EndIf

EndFunc

If you do want to use the Windows messages than you are forced to poll ClipGet somehow. :doh:

M23

ok, I'll follow your advice and see if it works, thanks :bye:

Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...