Jump to content

HotKeySet("{LEFT MOUSE BUTTON}", "MyFunc")


 Share

Recommended Posts

_IsPressed(1) ;left mouse

_IsPressed(2) ;right mouse

_IsPressed(4) ;middle mouse

_Ispressed(1) is not working for me wat am i doin wrong?

Code:

CODE
_IsPressed(1)

$var = MouseGetPos ()

MsgBox (0, $var[0], $var[1])

Link to comment
Share on other sites

The problem with that is I want to do something like this:

$key="{ENTER}"
$count = 0

HotKeySet($key, "function")

Func function()
    HotKeySet($key, "dummy")
    While _IsPressed('0D')  ;; OD is hex for {ENTER}
        $count += 1
    WEnd
    HotKeySet($key, "function")
EndFunc

Func dummy()
EndFunc

Sleep(10000)
MsgBox(0, 0, $count)

So that while you hold the key something happens, but the key itself doesnt get sent. Any thoughts?

Edited by T3k
Link to comment
Share on other sites

So that while you hold the key something happens, but the key itself doesnt get sent. Any thoughts?

You are on the right track, yet..

#include <misc.au3>
$key="{ENTER}"
$count = 0
HotKeySet($key, "function")

Sleep(10000)
MsgBox(0, 0, $count)

Func function()
    HotKeySet(@HotKeyPressed, "dummy") ;do it this way so multiple hotkeys can use this function
    While _IsPressed('0D')  ;; OD is hex for {ENTER} 
        Sleep(10) ;do something while key is held down..
    WEnd
    $count += 1 ;get exactly the number of times key was pressed
    HotKeySet(@HotKeyPressed, "function")
EndFunc

Func dummy()
EndFunc

Did this answer your question? Or am I missing what you are asking?

www.itoady.com

A* (A-star) Searching Algorithm - A.I. Artificial Intelligence bot path finding

Link to comment
Share on other sites

You are on the right track, yet..

#include <misc.au3>
$key="{ENTER}"
$count = 0
HotKeySet($key, "function")

Sleep(10000)
MsgBox(0, 0, $count)

Func function()
    HotKeySet(@HotKeyPressed, "dummy") ;do it this way so multiple hotkeys can use this function
    While _IsPressed('0D')  ;; OD is hex for {ENTER} 
        Sleep(10) ;do something while key is held down..
    WEnd
    $count += 1 ;get exactly the number of times key was pressed
    HotKeySet(@HotKeyPressed, "function")
EndFunc

Func dummy()
EndFunc

Did this answer your question? Or am I missing what you are asking?

What I meant to ask was, how do you do that, but with a mouse button instead of enter, since you can't HotKeySet a mouse button to dummy?
Link to comment
Share on other sites

i think that was answered back in the first post...

#Include <Misc.au3>
$key="{ENTER}"
$count = 0

HotKeySet($key, "function")

Func function()
    While _IsPressed('0D')  ;; OD is hex for {ENTER}
        $count += 1
    WEnd
EndFunc

Sleep(10000)
MsgBox(0, "Count", $count)

Just incase none of the above worked heres this.

Link to comment
Share on other sites

i think that was answered back in the first post...

It wasnt. Maybe I'm not explaining well enough. I want it so that while the user holds down, say, the right mouse button the script does something, and stops when the button is released. But while it's doing that, the right click shouldn't go through to the OS (which is what HotKeySet($key, "dummy") does, but not for mouse buttons). Did that make sense?

Edited by T3k
Link to comment
Share on other sites

  • 12 years later...

Sorry to relive the topic, but it seems that the doubt has not been resolved and this may be the doubt of others.
Here's a solution:

#include <MsgBoxConstants.au3>
#include <Misc.au3>


Local $n = 0

;When you press "END" key the process ends
HotKeySet("{END}", "_Terminate")
    Func _Terminate()
     Exit
    EndFunc

;When pressing "q" key displays count quantity
HotKeySet("q", "_InfoBox")
    Func _InfoBox()
     MsgBox(0,"",$n)
    EndFunc



;While holding down the left mouse button add up
While 1

    While _IsPressed(1)

        $n = $n + 1
        Sleep(500)

    WEnd

Sleep(100)
WEnd

 

Link to comment
Share on other sites

  • 1 year later...
On 11/13/2019 at 12:18 PM, Earthshine said:

Please do not resurrect old threads. Nobody cares at this point 

I do care. It would be kind to not blame others for answering an old question precisely. Even though you can't imagine that someone could be interested in the answer to this question, it doesn't mean that his assumption is wrong. His answer saved me some time and is in a good readable format.

So thanks to @Jonatas! 🤝

Link to comment
Share on other sites

  • Moderators

Assembler,

Welcome to the AutoIt forums.

As a general rule we discourage necroposting as the language has changed so much over the years that it is likely that the requested functionality has already been incorporated and/or the previously posted code will almost certainly not run in the current version of AutoIt without modification. But I am delighted to see that you found this particular post useful.

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

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