Jump to content

AutoHotKey


Recommended Posts

Opt("MouseCoordMode", 0)
Opt("Pixelcoordmode", 0)

Global $hot = HotKeySet("{SPACE}", "Pixelchecker")

Func Pixelchecker()
    Local $mousepos = MouseGetPos()
    Local $pixelpos[4]

    $pixelpos[0] = $mousepos[0] - 5 ;left
    $pixelpos[1] = $mousepos[1] + 5 ;top
    $pixelpos[2] = $mousepos[0] + 5 ;right
    $pixelpos[3] = $mousepos[1] - 5 ;bottom

    $pixelcheck = PixelChecksum($pixelpos[0], $pixelpos[1], $pixelpos[2], $pixelpos[3])

    While $pixelcheck = PixelChecksum($pixelpos[0], $pixelpos[1], $pixelpos[2], $pixelpos[3])
        Sleep(50)
    WEnd
    MouseClick("left")
EndFunc   ;==>Pixelchecker

So I got that far but my hotkeyset keeps running the function without me pressing space. Why would this be?

Link to comment
Share on other sites

Don't know why its activating itself for you, i stripped out the code in the space hotkey function and added a loop to test it and works fine for me.

Opt("MouseCoordMode", 0)
Opt("Pixelcoordmode", 0)

Global $Hot = HotKeySet("{SPACE}", "Pixelchecker")
HotKeySet("{ESC}","_Exit")

Func _Exit()
    MsgBox(0,"Finished","")
    Exit
EndFunc

Func Pixelchecker()
    MsgBox(0,"Pause","",1)
EndFunc   ;==>Pixelchecker


While 1
WEnd

edit - although you dont need the part Global $hot = , it still works if thats there.

Edited by Yoriz
GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.
Link to comment
Share on other sites

  • Moderators

blckpythn,

First, please do not use the term AutoHotKey here - it can upset some people. :(

Secondly, your code works fine for me - I added a ConsoleWrite line to show when we got to the waiting loop and it only fires if I press the HotKey:

Opt("MouseCoordMode", 0)
Opt("Pixelcoordmode", 0)

HotKeySet("{SPACE}", "Pixelchecker")
HotKeySet("{ESC}", "On_Exit")

While 1
    Sleep(10)
WEnd

Func Pixelchecker()
    Local $mousepos = MouseGetPos()
    Local $pixelpos[4]

    $pixelpos[0] = $mousepos[0] - 5 ;left
    $pixelpos[1] = $mousepos[1] + 5 ;top
    $pixelpos[2] = $mousepos[0] + 5 ;right
    $pixelpos[3] = $mousepos[1] - 5 ;bottom

    $pixelcheck = PixelChecksum($pixelpos[0], $pixelpos[1], $pixelpos[2], $pixelpos[3])

    ConsoleWrite("Entering waiting loop" & @CRLF)
    While $pixelcheck = PixelChecksum($pixelpos[0], $pixelpos[1], $pixelpos[2], $pixelpos[3])
        Sleep(500)
    WEnd

    MouseClick("left")
EndFunc   ;==>Pixelchecker

Func On_Exit()
    Exit
EndFunc

Is this all the code or is there any more which might fire the function?

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

  • Moderators

blckpythn,

HotKeySet merely returns 1 or 0 to show whether it was susccessful, so there is nothing to store to "call its return value with a msgbox". :)

You are aware that any use of the "Space" key once you have declared it as a HotKey will fire the function? Are you trying to use the "Space" key in another app with the script running? :(

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

  • Moderators

blckpythn,

The instant I press F5 to test the script the msgbox pops up saying that it returned a 1 for HotKeySet

That is the HotKey being set, NOT the function being run - is that what is causing the confusion?

When you run the code I posted earlier which included a ConsoleWrite, do you get the "Entering waiting loop" written in the SciTE console as soon as you press F5? Or do you have to press the "Space" key before it appears?

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

  • Moderators

blckpythn,

Let us look at the logic flow of your script:

1. You press the HotKey.

2. You take a PixelCheckSum of ths colours around the mouse position at that moment.

3. You wait until the PixelCheckSum changes.

4. You click the mouse at that same point.

So the mouse will only click when it gets out of this loop:

While $pixelcheck = PixelChecksum($pixelpos[0], $pixelpos[1], $pixelpos[2], $pixelpos[3])
    Sleep(500)
WEnd

Does the area under the mouse position ever change colour to enable this?

Or is the logic of the function wrong?

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

  • Moderators

Try this script. A small red square appears in the GUI, put the mouse over it and press "Space". 5 secs later the square changes to blue.

I get the correct strings written in the SciTE console - do you?

#include <GUIConstantsEx.au3>

Opt("MouseCoordMode", 0)
Opt("Pixelcoordmode", 0)

HotKeySet("{SPACE}", "Pixelchecker")

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

$hLabel = GUICtrlCreateLabel("", 10, 10, 20, 20)
GUICtrlSetBkColor(-1, 0xFF0000)

GUISetState()

ConsoleWrite("Ready!" & @CRLF)

While 1

    If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit

WEnd

Func Pixelchecker()
    Local $mousepos = MouseGetPos()
    Local $pixelpos[4]

    $pixelpos[0] = $mousepos[0] - 5 ;left
    $pixelpos[1] = $mousepos[1] + 5 ;top
    $pixelpos[2] = $mousepos[0] + 5 ;right
    $pixelpos[3] = $mousepos[1] - 5 ;bottom

    $pixelcheck = PixelChecksum($pixelpos[0], $pixelpos[1], $pixelpos[2], $pixelpos[3])

    ConsoleWrite("Entering waiting loop" & @CRLF)
    $ibegin = TimerInit()
    While $pixelcheck = PixelChecksum($pixelpos[0], $pixelpos[1], $pixelpos[2], $pixelpos[3])
        Sleep(500)
        If TimerDiff($iBegin) > 5000 Then GUICtrlSetBkColor($hLabel, 0x0000FF)
    WEnd

    ConsoleWrite("I am now clicking" & @CRLF)

    MouseClick("left")
EndFunc   ;==>Pixelchecker

M23

Edit: I see you have an answer - good. :(

Edited by Melba23

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

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...