Jump to content

Right click hotkey?


Recommended Posts

I made a script to press a hotkey every now and then:

while(5<7)

send("^!p")

Sleep(5000)

WEnd

but when I open right click menus this emulated key press will just kill them, so I wonder if you can make a hotkey to pause it like the help files say:

HotKeySet("{PAUSE}", "TogglePause")

Func TogglePause()

$Paused = NOT $Paused

While $Paused

sleep(100)

ToolTip('Script is "Paused"',0,0)

Sleep(20000) ; 20 seconds ought to be enough to finish working with the right click menu.

TogglePause()

WEnd

ToolTip("")

EndFunc

I added the italic part to the example script, but this only triggers on keyboard hotkey presses, so I'd like to let the hotkey be a mouse action, in my case right click, is that possible?

Thanks in Advance.

Stagnation

Link to comment
Share on other sites

Use _IsPressed :)

This code pops open a message box when you click:

#include <Misc.au3>
$user32 = DllOpen("user32.dll")
While 1
    If _IsPressed("01", $user32) Then
        MsgBox(0,"Event", "Boom!")
    EndIf
WEnd
Link to comment
Share on other sites

ok, so with your code I have

#include <Misc.au3>
$user32 = DllOpen("user32.dll")
While 1
    If _IsPressed("02", $user32) Then
        MsgBox(0,"Event", "Boom!")


    EndIf
WEnd

change 01 to 02 how should I continue?

I basically want it too loop until mouse2 is pressed, then it should sleep for a while and then continue looping

Edited by Stagnation
Link to comment
Share on other sites

So you want to pause the script when you open a right-click menu.

Well, pause it when you right click, and make it execute again when you click left.

Correct me if I'm wrong.

I will have a look and try it here.

EDIT:

I tried some things.

This should work:

#include <Misc.au3>
$user32 = DllOpen("user32.dll")
$count = 0

while true ;Repeat forever:
    If _IsPressed("01", $user32) Then ;If you click left,
        $pause = 0                      ;Turn Pause off
    ElseIf _IsPressed("02", $user32) Then ; If you click right,
        $pause = 1                      ;Turn pause on
    EndIf
    
    Sleep(250)  ;A shorter sleep time is required to make the _IsPressed work correctly
    if $count > 19 Then ;If this has looped 20 or more times (Making a total of 5000ms sleep time)
        $count = 0      ;reset the counter
        if not $pause then send("^!p") ;and send the keystrokes when pause is turned off
    EndIf
WEnd
Edited by Before
Link to comment
Share on other sites

So you want to pause the script when you open a right-click menu.

Well, pause it when you right click, and make it execute again when you click left.

Correct me if I'm wrong.

I will have a look and try it here.

EDIT:

I tried some things.

This should work:

#include <Misc.au3>
$user32 = DllOpen("user32.dll")
$count = 0

while true ;Repeat forever:
    If _IsPressed("01", $user32) Then ;If you click left,
        $pause = 0                      ;Turn Pause off
    ElseIf _IsPressed("02", $user32) Then ; If you click right,
        $pause = 1                      ;Turn pause on
    EndIf
    
    Sleep(250)  ;A shorter sleep time is required to make the _IsPressed work correctly
    if $count > 19 Then ;If this has looped 20 or more times (Making a total of 5000ms sleep time)
        $count = 0      ;reset the counter
        if not $pause then send("^!p") ;and send the keystrokes when pause is turned off
    EndIf
WEnd

I used the code you used, and noticed that it never sent the keys, so I added a simple $count = $count + 1 at the end to see if it worked.

so after ~5secs I got an error about a variable being used without being declared, but then when I restrted it, it seems to work, it sends the key like it should and seems to pause after right clicks and resumes to send the key after left clicks. Thank you very much!

Link to comment
Share on other sites

I've made this sometimes:

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

HotKeySet("{ESC}", "closeGUI")
Global $isMHK = 0
Global $m_checkParam[4], $user_dll = DllOpen("user32.dll")

$gui = GUICreate('Test Mouse-Hotkey')
GUISetOnEvent($GUI_EVENT_CLOSE, 'closeGUI')
GUICtrlCreateLabel('Close with <ESC> oder |X|', 50, 20, 150)
GUICtrlCreateLabel('Mouse:', 10, 78, 50)
$coMouse = GUICtrlCreateCombo('left', 70, 75, 50)
GUICtrlSetData(-1, 'right|middle', 'left')
GUICtrlCreateLabel('+ Key:', 150, 78, 50)
$coKey = GUICtrlCreateCombo('0', 190, 75, 40)
$sItem = ''
For $i = 49 To 90
    If $i = 58 Then $i = 65
    $sItem &= Chr($i) & '|'
Next
GUICtrlSetData($coKey, StringTrimRight($sItem, 1), '0')
$btSetMHK = GUICtrlCreateButton('Set Mouse-Hotkey', 40, 120, 180, 20)
GUICtrlSetOnEvent(-1, 'setMHK')
GUISetState()


While 1
    Sleep(20)
WEnd

Func closeGUI()
    If $isMHK Then HotKeyMouseSet()
    DllClose($user_dll)
    Exit
EndFunc   ;==>closeGUI

Func setMHK()
    If $isMHK Then
        HotKeyMouseSet()
        GUICtrlSetData($btSetMHK, 'Set Mouse-HotKey')
        WinSetTitle($gui, '', 'Hotkey is now deleted')
    Else
        HotKeyMouseSet(GUICtrlRead($coMouse), GUICtrlRead($coKey), 'test')
        GUICtrlSetData($btSetMHK, 'Delete Mouse-HotKey')
        WinSetTitle($gui, '', 'current MHK: ' & StringUpper(GUICtrlRead($coMouse)) & ' + ' & GUICtrlRead($coKey))
    EndIf
    $isMHK = BitXOR($isMHK, 1)
EndFunc   ;==>setMHK

Func HotKeyMouseSet($m_button = '', $key = '', $func = '', $r_time = 1000)
    If Not $m_button Then Return AdlibDisable()
    If Not $key Or Not $func Then Return SetError(1, 0, 0)
    If Not IsString($func) Then Return SetError(2, 0, 0)
    $key = Asc(StringUpper($key))
    If $m_button = 'left' Then
        $m_checkParam[0] = '01'
    ElseIf $m_button = 'right' Then
        $m_checkParam[0] = '02'
    ElseIf $m_button = 'middle' Then
        $m_checkParam[0] = '04'
    Else
        Return SetError(3, 0, 0)
    EndIf
    $m_checkParam[1] = $key
    $m_checkParam[2] = $func
    $m_checkParam[3] = $r_time
    Local $ret
    Do 
        For $i = 1 To 256
            $ret = DllCall($user_dll, "int", "GetAsyncKeyState", "int", "0x" & Hex($i, 2))
        Next
    Until $ret[0] = 0
    AdlibEnable('_checkMouse', 100)
EndFunc   ;==>HotKeyMouseSet

Func _checkMouse()
    Local $ts, $ret
    If _IsPressed($m_checkParam[0], $user_dll) Then
        $ts = TimerInit()
        Do
            $ret = DllCall($user_dll, "int", "GetAsyncKeyState", "int", "0x" & Hex($m_checkParam[1], 2))
            If $ret[0] Then Return Call($m_checkParam[2])
        Until TimerDiff($ts) > $m_checkParam[3]
    EndIf
EndFunc   ;==>_checkMouse

Func test()
    MsgBox(0, 'MausHotKey', 'Hotkey are used')
EndFunc   ;==>test

HKM.au3

Best Regards BugFix  

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