Sign in to follow this  
Followers 0
Benji

Just a quickie...

11 posts in this topic

total nub here just trying to grasp the basics :D could anyone tell me how i would bind either left or right mouse button so when it is clicked it would perform the rest of the script. i.e. When i left click in notepad it types "Benji is not so bright when it comes to computers" :)

Thanks in advance

Ben

Share this post


Link to post
Share on other sites



any ideas? :)

Share this post


Link to post
Share on other sites

this doesn't work when you click on notepad, but works when you click on the gui, i'm sure someone can easily figure out how do what your wanting.

; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.1.0
; Author:        A.N.Other <myemail@nowhere.com>
;
; Script Function:
;   Template AutoIt script.
;
; ----------------------------------------------------------------------------

; Script Start - Add your code below here

#include <GUIConstants.au3>
Opt("GUIOnEventMode",1)
Opt("WinTitleMatchMode",2)
GUICreate("Benji")
GUISetOnEvent($GUI_EVENT_PRIMARYDOWN,"LeftClick")
GUISetOnEvent($GUI_EVENT_CLOSE,"Close")

GUISetState()
while 1
    Sleep ( 10 )
WEnd

Func LeftClick()
    GUISetState(@SW_HIDE)
    If(Not ProcessExists("Notepad.exe")) Then
        Run("notepad")
        Sleep ( 1000 )
    EndIf
    WinWait("Notepad")
    Winactivate("Notepad")
    Send("Benji is not so bright when it comes to computers")
    GUISetState(@SW_SHOW)
EndFunc

Func Close()
    Exit
EndFunc

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

get the controlid or classname to notepads edit window and set an 'onevent' to that

$handle = ControlGetHandle("Untitled - Notepad", "", "Edit1")

GUICtrlSetOnEvent ( $handle, "function" )

Edited by quaizywabbit

[u]Do more with pre-existing apps![/u]ANYGUIv2.8

Share this post


Link to post
Share on other sites

get the controlid or classname to notepads edit window and set an 'onevent' to that

<{POST_SNAPBACK}>

You've tested this theory and it works, no?

Share this post


Link to post
Share on other sites

thanks for the response. where would i put that extra bit of script quaizywabbit in gafrost's original script?

thanks Ben

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

works, but not perfect.

#include <GUIConstants.au3>
Opt("GUIOnEventMode",1)

$GUI_WIN = GUICreate("Benji")

GUISetOnEvent($GUI_EVENT_PRIMARYDOWN,"PrimaryDown")
GUISetOnEvent($GUI_EVENT_CLOSE,"Close")

If(Not ProcessExists("Notepad.exe")) Then
    Run("notepad")
EndIf

Opt("WinTitleMatchMode",2)


GUISetState()
WinActivate($GUI_WIN)

while 1
    Sleep ( 10 )
WEnd

Func LeftClick()
    Winactivate("Notepad")
    ControlSend("Notepad","","Edit1","Benji is not so bright when it comes to computers")
EndFunc

Func PrimaryDown()
    LeftClick()
EndFunc

Func Close()
    Exit
EndFunc

only seems to work if you select notepad from the task bar.

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

while 1
    $a = ControlGetFocus("Untitled - Notepad")
    Select
    case $a = ""
        ContinueLoop
    case $a = "Edit1"
        Leftclick()
    EndSelect

    Sleep ( 300 )
WEnd

I had something working along these lines....but then I screwed it up :)

I Kept Notepad deactivated, by using Winactivate("Benji"), so when you clicked Notepads window, it would trigger...

Edited by quaizywabbit

[u]Do more with pre-existing apps![/u]ANYGUIv2.8

Share this post


Link to post
Share on other sites

get the controlid or classname to notepads edit window and set an 'onevent' to that

$handle = ControlGetHandle("Untitled - Notepad", "", "Edit1")

GUICtrlSetOnEvent ( $handle, "function" )

<{POST_SNAPBACK}>

This cannot work. Reread the doc please.

GUI Function are using ControlID as parameter not handles. :)

Share this post


Link to post
Share on other sites

yep....missed that earlier, thanks..


[u]Do more with pre-existing apps![/u]ANYGUIv2.8

Share this post


Link to post
Share on other sites

whats about this solution ? maybe this works for you:

AutoItSetOption ( "WinTitleMatchMode", 2)
AutoItSetOption ( "TrayIconDebug", 1)

$write_notepad = ""
$i = 1

While $i = 1
    Select
    Case _IsPressed('01');Left Mouse Button
            $win_handle = WinGetHandle ('')
            $win_pos = WinGetPos ($win_handle)
            $win_title = WinGetTitle($win_handle)
            ToolTip('You pressed left...' & @CRLF & $win_title& @CRLF & 'X: ' & $win_pos[0] & ' Y: ' & $win_pos[1] & @CRLF & 'Width: ' & $win_pos[2] & ' px' & @CRLF & 'Height: ' & $win_pos[3] & ' px')
        ;feel free to do whatever you want until here
            If $write_notepad <> 1 Then
                If ProcessExists ('notepad.exe') Then
                    WinActivate ('Notepad')
                    Send("Benji is not so bright when it comes to computers")
                Else
                    Run('notepad.exe')
                    WinWaitActive ('Notepad')
                    Send("Benji is not so bright when it comes to computers")
                EndIf
                $write_notepad = 1;Prevents from writing the text over and over again
            EndIf
        Case _IsPressed('02');Right Mouse Button
            $mouse_pos = MouseGetPos ()
            ToolTip('You pressed right,' & @CRLF & 'Mouse is at ' & $mouse_pos[0] & 'x' & $mouse_pos[1])
            If _IsPressed('04') Then
                MsgBox (0,'clicks detected','left AND middle ???' & @CRLF & 'oh boy, you`re crazy.....')
                $win_pos = WinGetPos ('')
            EndIf

        Case _IsPressed('04');Middle Mouse Button
            ToolTip('Middleclick')

        Case _IsPressed('1B');[ESC]
            $i = 0
            MsgBox(0, '', 'END OF SCRIPT')

        Case Else
            ToolTip('')
    EndSelect
    sleep (10)
WEnd


Func _IsPressed($HexKey)
   Local $AR
   $HexKey = '0x' & $HexKey
   $AR = DllCall('user32','int','GetAsyncKeyState','int',$HexKey)
   If NOT @Error And BitAND($AR[0],0x8000) = 0x8000 Then Return 1
   Return 0
EndFunc

Share this post


Link to post
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
Sign in to follow this  
Followers 0