Jump to content

IsPressed twice?


someone
 Share

Recommended Posts

Hi everyone,

I'm trying to make a script that calls a function when the user double-clicks on the middle mouse button. Everything works fine if I'm only 'listening' for one instance of IsPressed, but I have no idea how to code for 2.

I know its not entirely simple as you have to use a timestamp to see how close the two presses are to each other. I don't even have any code to show except the code for a normal IsPressed function. I have tried a bunch of things but haven't saved any of the non working code...

#include <Misc.au3>

$dll = DllOpen("user32.dll")

While 1
    Sleep (20)
    If _IsPressed("04", $dll) Then
        test()
    EndIf

    WEnd
DllClose($dll)

Func test()
    MsgBox(0,"", "yay")
EndFunc

Also I have looked around the forum with no luck. Thanks everyone for your help!

Andrew

While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd
Link to comment
Share on other sites

This is only a guess, as I have no means of testing it right now, but give it a try and see what happens!

#include <Misc.au3>

$dll = DllOpen("user32.dll")

While 1
    Sleep (20)
    If _IsPressed("04", $dll) and _IsPressed("04", $dll) Then
        test()
    EndIf

    WEnd
DllClose($dll)

Func test()
    MsgBox(0,"", "yay")
EndFunc
oÝ÷ Úæk&Þjëh×6
    Sleep (20)
    If _IsPressed("04", $dll) Then
        if _IsPressed("04", $dll) Then
            test()
        EndIf
    EndIf
Edited by improbability_paradox
Link to comment
Share on other sites

  • Moderators

While 1
    Sleep(10)
    If _IsDoubleClick('04', 1000) Then MsgBox(64, 'Info', 'You double clicked the middle mouse button.')
WEnd

Func _IsDoubleClick($sHex, $iTimeDelay = 2000);adjust the time delay default parameter if you need to
    Local $nTimer = TimerInit()
    If __IsPressed($sHex) = 0 Then Return SetError(1, 0, 0)
    Do
    Until __IsPressed($sHex) = 0
    While 1
        If __IsPressed($sHex) Then Return 1
        If TimerDiff($nTimer) >= $iTimeDelay Then Return SetError(2, 0, 0)
    WEnd
EndFunc

Func __IsPressed($v_R, $v_dll = 'user32.dll')
    $v_R = DllCall($v_dll, 'int', 'GetAsyncKeyState', 'int', '0x' & $v_R)
    Return (Not @error And BitAND($v_R[0], 0x8000) = 0x8000) * 1
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

No unfortunately neither of those work... I was thinking that the answer would probably be creating a count and when that count reaches 2 it calls the function... I couldn't get that working in code though.... something like

$doublecount = 0

If _IsPressed("04", $dll) Then

$doublecount = $doublecount + 1

If $doublecount = 2 Then

test()

but that doesn't work.... thanks for the ideas though

While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd
Link to comment
Share on other sites

I posted my answer to improbability paradox before SmOke N posted...

That works great - I think it would have taken me forever to figure that out. Thanks alot improbability_paradox and as always thanks SmOke_N

PS. SmOke_N... would you mind if I posted that in the autoit snippet database? I don't want to take credit for it but thats a nice piece of code... thanks

While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd
Link to comment
Share on other sites

  • Moderators

PS. SmOke_N... would you mind if I posted that in the autoit snippet database? I don't want to take credit for it but thats a nice piece of code... thanks

I think this is a crude method is why I've never done it... personally I don't like how it interrupts the script even if it is for 1 or 2 seconds.

If I were going to do it for myself, I'd use Larry's hook.dll...

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Yes... it only occured to me after the fact that some form of delay would need to be implemented between instances of checking IsPressed(). my revised idea (along the line's of what SmOke_N wrote) is a little different...

#include <Misc.au3>
local $PressedTS, $TimeToPress=1000
while
if _IsPressed("04") then
if TimerDiff($PressedTS)<$TimeToPress then
$PressedTS=0
;do what you want to here, the button was double clicked
else
$PressedTS=TimerInit()
endif
endif
sleep(50)
wend

But then, why re-invent the wheel? Or in other words, if you already have a solution that works (SmOke_N's) go with that!

Also note that this isn't tested either, as I am not at home right now

Link to comment
Share on other sites

I think this is a crude method is why I've never done it... personally I don't like how it interrupts the script even if it is for 1 or 2 seconds.

If I were going to do it for myself, I'd use Larry's hook.dll...

Good point. I hadn't read your post before my most recent reply, and I think that if my idea does work then it would not pose the problem of interrupting the script

Link to comment
Share on other sites

I think this is a crude method is why I've never done it... personally I don't like how it interrupts the script even if it is for 1 or 2 seconds.

If I were going to do it for myself, I'd use Larry's hook.dll...

Ha I guess that shows how much I know about autoit... :whistle: I'll look into using larry's hook.dll, but using your method seems to work very good for my purpose. If I come up with anything I'll post it in the examples script.

Thanks again everyone.

While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd
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...