Hallo Leute,
habe mal wieder eine Frage und zwar, wie kann ich prüfen ob eine Maustaste losgelassen wird?
Z.B.:
Do
...
Until ... >> Sobald Maustaste losgelassen wird << ....
Danke schon mal im vorraus.
Hallo Leute,
habe mal wieder eine Frage und zwar, wie kann ich prüfen ob eine Maustaste losgelassen wird?
Z.B.:
Do
...
Until ... >> Sobald Maustaste losgelassen wird << ....
Danke schon mal im vorraus.
Func MousePressed()
Local $user32 = DllOpen('user32.dll')
Local $MousePressed = False
If _IsPressed('01', $user32) Then
$MousePressed = True
$Time = TimerInit()
While _IsPressed('01', $user32)
Sleep(10)
WEnd
$TimePressed = TimerDiff($Time)
Local $a_R[3]
$a_R[0] = 2
$a_R[1] = $TimePressed
$a_R[2] = $MousePressed
EndIf
Return $a_R
EndFunc
Hier ist ne schöne UDF dafür:
#include-once
[/autoit] [autoit][/autoit] [autoit]Global Const $WH_MOUSE_LL = 14
[/autoit] [autoit][/autoit] [autoit]Global Const $MOUSE_MOVE_EVENT = 512
Global Const $MOUSE_PRIMARYDOWN_EVENT = 513
Global Const $MOUSE_PRIMARYUP_EVENT = 514
Global Const $MOUSE_SECONDARYDOWN_EVENT = 516
Global Const $MOUSE_SECONDARYUP_EVENT = 517
Global Const $MOUSE_WHELLDOWN_EVENT = 519
Global Const $MOUSE_WHELLUP_EVENT = 520
Global Const $MOUSE_WHELLSCROLL_EVENT = 522
Global Const $MOUSE_EXTRABUTTONDOWN_EVENT = 523
Global Const $MOUSE_EXTRABUTTONUP_EVENT = 524
Global $hKey_Proc = -1
Global $hM_Module = -1
Global $hM_Hook = -1
Global $aMouse_Events[1][1]
Func OnAutoItExit()
If IsArray($hM_Hook) And $hM_Hook[0] > 0 Then
DllCall("user32.dll", "int", "UnhookWindowsHookEx", "hwnd", $hM_Hook[0])
$hM_Hook[0] = 0
EndIf
If IsPtr($hKey_Proc) Then
DllCallbackFree($hKey_Proc)
$hKey_Proc = 0
EndIf
EndFunc
Func _MouseSetOnEvent($iEvent, $sFuncName="", $sParam1="", $sParam2="", $hTargetWnd=0, $iBlockDefProc=1)
If $sFuncName = "" Then ;Unset Event
If $aMouse_Events[0][0] < 1 Then Return 0
Local $aTmp_Mouse_Events[1][1]
For $i = 1 To $aMouse_Events[0][0]
If $aMouse_Events[$i][0] <> $iEvent Then
$aTmp_Mouse_Events[0][0] += 1
ReDim $aTmp_Mouse_Events[$aTmp_Mouse_Events[0][0]+1][6]
$aTmp_Mouse_Events[$aTmp_Mouse_Events[0][0]][0] = $aMouse_Events[$i][0]
$aTmp_Mouse_Events[$aTmp_Mouse_Events[0][0]][1] = $aMouse_Events[$i][1]
$aTmp_Mouse_Events[$aTmp_Mouse_Events[0][0]][2] = $aMouse_Events[$i][2]
$aTmp_Mouse_Events[$aTmp_Mouse_Events[0][0]][3] = $aMouse_Events[$i][3]
$aTmp_Mouse_Events[$aTmp_Mouse_Events[0][0]][4] = $aMouse_Events[$i][4]
$aTmp_Mouse_Events[$aTmp_Mouse_Events[0][0]][5] = $aMouse_Events[$i][5]
EndIf
Next
$aMouse_Events = $aTmp_Mouse_Events
If $aMouse_Events[0][0] < 1 Then OnAutoItExit()
Return 1
EndIf
If $aMouse_Events[0][0] < 1 Then
$hKey_Proc = DllCallbackRegister("_Mouse_Events_Handler", "int", "int;ptr;ptr")
$hM_Module = DllCall("kernel32.dll", "hwnd", "GetModuleHandle", "ptr", 0)
$hM_Hook = DllCall("user32.dll", "hwnd", "SetWindowsHookEx", "int", $WH_MOUSE_LL, _
"ptr", DllCallbackGetPtr($hKey_Proc), "hwnd", $hM_Module[0], "dword", 0)
EndIf
$aMouse_Events[0][0] += 1
ReDim $aMouse_Events[$aMouse_Events[0][0]+1][6]
$aMouse_Events[$aMouse_Events[0][0]][0] = $iEvent
$aMouse_Events[$aMouse_Events[0][0]][1] = $sFuncName
$aMouse_Events[$aMouse_Events[0][0]][2] = $sParam1
$aMouse_Events[$aMouse_Events[0][0]][3] = $sParam2
$aMouse_Events[$aMouse_Events[0][0]][4] = $hTargetWnd
$aMouse_Events[$aMouse_Events[0][0]][5] = $iBlockDefProc
EndFunc
Func _Mouse_Events_Handler($nCode, $wParam, $lParam)
Local $iEvent = BitAND($wParam, 0xFFFF)
If $aMouse_Events[0][0] < 1 Then
OnAutoItExit()
Return 0
EndIf
For $i = 1 To $aMouse_Events[0][0]
If $aMouse_Events[$i][0] = $iEvent Then
If $aMouse_Events[$i][4] <> 0 And Not _IsHoveredWnd($aMouse_Events[$i][4]) Then Return 0 ;Allow default processing
Local $sExec = "Call($aMouse_Events[$i][1]"
For $j = 2 To 3
If $aMouse_Events[$i][$j] <> "" Then $sExec &= ", " & $aMouse_Events[$i][$j]
Next
$sExec &= ")"
$iRet = Execute($sExec)
If $aMouse_Events[$i][5] = -1 Then Return $iRet
Return $aMouse_Events[$i][5] ;Block default processing (or not :))
EndIf
Next
EndFunc
Func _IsHoveredWnd($hWnd)
Local $iRet = False
Local $aWin_Pos = WinGetPos($hWnd)
Local $aMouse_Pos = MouseGetPos()
If $aMouse_Pos[0] >= $aWin_Pos[0] And $aMouse_Pos[0] <= ($aWin_Pos[0] + $aWin_Pos[2]) And _
$aMouse_Pos[1] >= $aWin_Pos[1] And $aMouse_Pos[1] <= ($aWin_Pos[1] + $aWin_Pos[3]) Then $iRet = True
Local $aRet = DllCall("user32.dll", "int", "WindowFromPoint", _
"long", $aMouse_Pos[0], _
"long", $aMouse_Pos[1])
If Not WinActive($hWnd) Or ($aRet[0] <> $hWnd And Not $iRet) Then $iRet = False
Return $iRet
EndFunc
Beispiel:
#include <MouseSetOnEvent_UDF.au3>
[/autoit] [autoit][/autoit] [autoit]HotKeySet ( "{ESC}","_ende" )
[/autoit] [autoit][/autoit] [autoit]_MouseSetOnEvent($MOUSE_PRIMARYUP_EVENT, "_PrimeUp")
[/autoit] [autoit][/autoit] [autoit]Do
Sleep( 100 )
Until ""
Func _PrimeUp()
Run ( "calc.exe")
EndFunc
Func _ende()
Exit
EndFunc
Danke für eure Antwort.
Komplizierte Sache, nur um zu prüfen ob die Maustaste losgelassen wird.
Du musst die Funktion aufrufen und die Rückgabe auswerten... wenn das zu viel ist...
peethebee
Meinst du damit die UDF von Greek?
Hallo Mehmex,
falls du im OnEventModus programmierst geht es auch einfacher,
[autoit]#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Opt('GUIOnEventMode', 1)
Local $hMainGui = GUICreate("Testaufruf für EditBox", 400, 280, 40, 150, BitOR($WS_MINIMIZEBOX, $WS_MAXIMIZEBOX, $WS_SIZEBOX))
GUISetOnEvent($GUI_EVENT_CLOSE, '_End')
GUISetOnEvent($GUI_EVENT_PRIMARYUP, '_Show_MSG'); <================= nämlich so
Local $hlblSpalte = GUICtrlCreateLabel("", 10, 10, 200, 25)
GUICtrlSetResizing(-1, $GUI_DOCKSIZE + $GUI_DOCKLeft + $GUI_DOCKTOP)
GUICtrlCreateButton('&Buchstaben (a-m)', 200, 10, 150, 25)
GUICtrlSetOnEvent(-1, '_CallSpalte')
Local $hlblZeile = GUICtrlCreateLabel("", 10, 50, 200, 25)
GUICtrlSetResizing(-1, $GUI_DOCKSIZE + $GUI_DOCKLeft + $GUI_DOCKTOP)
GUICtrlCreateButton('&Zahl (1-12', 200, 50, 150, 25)
GUICtrlSetResizing(-1, $GUI_DOCKSIZE + $GUI_DOCKRIGHT + $GUI_DOCKTOP)
GUICtrlSetOnEvent(-1, '_CallZeile')
Local $hlblErg = GUICtrlCreateLabel("", 10, 90, 200, 25)
GUICtrlSetResizing(-1, $GUI_DOCKSIZE + $GUI_DOCKLeft + $GUI_DOCKTOP)
GUICtrlCreateButton('be&enden', 200, 130, 150, 25)
GUICtrlSetOnEvent(-1, '_End')
GUICtrlSetResizing(-1, $GUI_DOCKSIZE + $GUI_DOCKRIGHT + $GUI_DOCKTOP)
GUISetState()
While 1
Sleep(120)
WEnd
Func _End()
GUIDelete($hMainGui)
Exit
EndFunc ;==>_End
Func _Show_MSG()
MsgBox(0,"primäre (linke) Maustaste","wurde losgelassen",5000,$hMainGui)
EndFunc
Func _CallSpalte()
MsgBox(0,"Spalte","",0,$hMainGui)
EndFunc
Func _CallZeile()
MsgBox(0,"Spalte","",0,$hMainGui)
EndFunc
mfg (Auto)Bert
Danke für die Antwort. Ich möchte es aber gerne für einen bestimmten Button etc. benutzen.
Das geht aber nur wenn die Maus schon über dem GUI gedrückt worden ist, wollte nämlich auch erst $GUI_EVENT_PRIMARYUP empfehlen.