Jump to content

Recommended Posts

Posted

Is there a way to do the equivalent of hotkeyset() but use mouse buttons? e.g. when i right click a certain function is run?

Thanks!

T3k

Posted

  Toady said:

_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])

Posted (edited)

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
Posted

  T3k said:

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

Posted

  Toady said:

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?
Posted

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.

Posted (edited)

  Quote

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
  • 12 years later...
Posted

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

 

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

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

Expand  

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! 🤝

  • Moderators
Posted

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:

  Reveal hidden contents

 

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
  • Recently Browsing   0 members

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