Jump to content

Mouseclick on a hotkey?


 Share

Recommended Posts

No you can't bind a mouseclick as a hotkey. Maybe something like this could work for you?

#include <Misc.au3>
$dll = DllOpen("user32.dll")
While 1
    sleep(10)
    If _IsPressed("01", $dll) AND _IsPressed("11", $dll) AND _IsPressed("12", $dll) Then
        Consolewrite('Pressed' & @CRLF)
        ExitLoop
    EndIf
WEnd
DllClose($dll)

Also maybe you could bind CTRL and ALT to a hotkey, then in the function check for a few seconds if _IsPressed("01", $dll) (Left Mouseclick) and if it is proceed? Just a couple ideas.

Link to comment
Share on other sites

Here are a solution for Mouse-HotKey. Function HotKeyMouseSet() includes parameter $r_time. This is the maximum delay between mouse-click and key-down. By default it's 1000 ms.

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