Kmeersch Posted August 18, 2008 Share Posted August 18, 2008 How can we capture a double mouseclick event in a standard Windows application? (NOT in an AutoIT GUI) thx! Link to comment Share on other sites More sharing options...
SaphuA Posted August 18, 2008 Share Posted August 18, 2008 Not sure if there is a standard function for that. If there isn't, you could check the time between two clicks and determine for yourself if it was a double click or not. Might not be too accurate though. http://www.saphua.com/ Link to comment Share on other sites More sharing options...
Joscpe Posted August 18, 2008 Share Posted August 18, 2008 (edited) Try this:#include <Misc.au3> Dim $click=0,$clickTimer=-1 ;Create GUI and While script here. Func doubleClick() If _IsPressed("01") Then Sleep(10) If Not _IsPressed("01") Then $click = $click + 1 If $clickTimer=-1 Or TimerDiff($clickTimer) >= 1200 Then $clickTimer=TimerInit() $click=0 EndIf EndIf If $click = 2 Then $click = 0 Return 1 EndIf EndIf EndFuncExample:#include <Misc.au3> GUICreate("WindowTitle") GUISetState() Dim $click=0,$clickTimer=-1 While 1 Sleep(10) if doubleClick() Then MsgBox(0, "Double Click", "You have double clicked.") WEnd Func doubleClick() If _IsPressed("01") Then Sleep(10) If Not _IsPressed("01") Then $click = $click + 1 If $clickTimer=-1 Or TimerDiff($clickTimer) > 1200 Then $clickTimer=TimerInit() $click=0 EndIf EndIf If $click = 2 Then $click = 0 Return 1 EndIf EndIf EndFuncEdit:I had to fix the function a bit, it doesn't seem to work the greatest, try tweaking the sleep and the timer.Edit:This example seems to work pretty well for me.#include <Misc.au3> GUICreate("WindowTitle") GUISetState() Dim $click=0,$clickTimer=-1 While 1 if doubleClick() Then MsgBox(0, "Double Click", "You have double clicked.", 1) WEnd Func doubleClick() If _IsPressed("01") Then Sleep(20) If Not _IsPressed("01") Then $click = $click + 1 If $clickTimer=-1 Or TimerDiff($clickTimer) >= 3000 Then $clickTimer=TimerInit() $click=0 EndIf EndIf If $click = 2 Then $click = 0 Return 1 EndIf EndIf EndFunc Edited August 18, 2008 by Joscpe -Joscpe Link to comment Share on other sites More sharing options...
rasim Posted August 18, 2008 Share Posted August 18, 2008 KmeerschWelcome!Try this:expandcollapse popupHotKeySet("{Esc}", "_Exit") Global Const $WH_MOUSE_LL = 14 Global $DblClk_Speed = RegRead("HKCU\Control Panel\Mouse", "DoubleClickSpeed") ;Getting system double click speed If @error Then $DblClk_Speed = 500 Global $Timer = 0 Global $hKeyProc = DllCallbackRegister ("_Mouse_Handler", "int", "int;ptr;ptr") Global $hmod = DllCall("kernel32.dll", "hwnd", "GetModuleHandle", "ptr", 0) Global $hHook = DllCall("user32.dll", "hwnd", "SetWindowsHookEx", "int", $WH_MOUSE_LL, _ "ptr", DllCallbackGetPtr($hKeyProc), "hwnd", $hmod[0], "dword", 0) While 1 Sleep(100) WEnd Func _Mouse_Handler($nCode, $wParam, $lParam) If $nCode < 0 Then Local $aRet = DllCall("user32.dll", "long", "CallNextHookEx", "hwnd", $hHook[0], "int", $nCode, "wparam", $wParam, _ "lparam", $lParam) Return $aRet[0] EndIf Switch BitAND($WParam, 0xFFFF) Case 513 ;Primary Down _CheckInterval() EndSwitch EndFunc Func _CheckInterval() If $Timer = 0 Then $Timer = TimerInit() Else If TimerDiff($Timer) <= 500 Then ConsoleWrite("!> Double click" & @LF) $Timer = TimerInit() EndIf EndFunc Func _Exit() DllCall("user32.dll", "int", "UnhookWindowsHookEx", "hwnd", $hHook[0]) DllCallbackFree($hKeyProc) Exit EndFunc Link to comment Share on other sites More sharing options...
Joscpe Posted August 18, 2008 Share Posted August 18, 2008 Kmeersch Welcome! Try this: expandcollapse popupHotKeySet("{Esc}", "_Exit") Global Const $WH_MOUSE_LL = 14 Global $DblClk_Speed = RegRead("HKCU\Control Panel\Mouse", "DoubleClickSpeed") ;Getting system double click speed If @error Then $DblClk_Speed = 500 Global $Timer = 0 Global $hKeyProc = DllCallbackRegister ("_Mouse_Handler", "int", "int;ptr;ptr") Global $hmod = DllCall("kernel32.dll", "hwnd", "GetModuleHandle", "ptr", 0) Global $hHook = DllCall("user32.dll", "hwnd", "SetWindowsHookEx", "int", $WH_MOUSE_LL, _ "ptr", DllCallbackGetPtr($hKeyProc), "hwnd", $hmod[0], "dword", 0) While 1 Sleep(100) WEnd Func _Mouse_Handler($nCode, $wParam, $lParam) If $nCode < 0 Then Local $aRet = DllCall("user32.dll", "long", "CallNextHookEx", "hwnd", $hHook[0], "int", $nCode, "wparam", $wParam, _ "lparam", $lParam) Return $aRet[0] EndIf Switch BitAND($WParam, 0xFFFF) Case 513 ;Primary Down _CheckInterval() EndSwitch EndFunc Func _CheckInterval() If $Timer = 0 Then $Timer = TimerInit() Else If TimerDiff($Timer) <= 500 Then ConsoleWrite("!> Double click" & @LF) $Timer = TimerInit() EndIf EndFunc Func _Exit() DllCall("user32.dll", "int", "UnhookWindowsHookEx", "hwnd", $hHook[0]) DllCallbackFree($hKeyProc) Exit EndFuncWow, yours works much better! -Joscpe Link to comment Share on other sites More sharing options...
Kmeersch Posted August 19, 2008 Author Share Posted August 19, 2008 GREAT! thx both of you!! Link to comment Share on other sites More sharing options...
Kmeersch Posted August 19, 2008 Author Share Posted August 19, 2008 When i use the function getcontrolfocus(), the script detects no more DBLClick. example: ControlGetFocus("Oazis") any Link to comment Share on other sites More sharing options...
rasim Posted August 19, 2008 Share Posted August 19, 2008 KmeerschShow your code. Link to comment Share on other sites More sharing options...
Kmeersch Posted August 19, 2008 Author Share Posted August 19, 2008 expandcollapse popup;----------------------------------------- ;controle of script al actief is $winTitel = "Script huisarts toestemmingsformulier" If WinExists($winTitel) Then Exit AutoItWinSetTitle($winTitel) AutoItSetOption("TrayIconHide",1) ;----------------------------------------- $workstation = @ComputerName $osuser = "kl_groeninghe\"&@UserName ;wordt meegegeven door Imprivata $oazis_user=$CmdLine[1] $a="" ;----------------------------------------- ;Mouse Dblclick event opvangen Global Const $WH_MOUSE_LL = 14 Global $DblClk_Speed = RegRead("HKCU\Control Panel\Mouse", "DoubleClickSpeed");Getting system double click speed If @error Then $DblClk_Speed = 500 Global $Timer = 0 Global $hKeyProc = DllCallbackRegister ("_Mouse_Handler", "int", "int;ptr;ptr") Global $hmod = DllCall("kernel32.dll", "hwnd", "GetModuleHandle", "ptr", 0) Global $hHook = DllCall("user32.dll", "hwnd", "SetWindowsHookEx", "int", $WH_MOUSE_LL, _ "ptr", DllCallbackGetPtr($hKeyProc), "hwnd", $hmod[0], "dword", 0) ;----------------------------------------- #include "Array.au3" #Include<file.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <Misc.au3> ;$dll = DllOpen("user32.dll") while WinExists("Oazis") ;$a = ControlGetFocus("Oazis") ;bij het oproepen van het ontslag scherm mag er geen vraagstelling komen voor informed consent (ze gebruiken dezelfde objecten) $wintext = stringinstr(WinGetText("Oazis", ""),"ontslag van een patient",2) ;muisklik opvangen ;~ If WinActive("Oazis") Then ;~ $pos=MouseGetPos() ;~ $color = Hex(PixelGetColor($pos[0],$pos[1])) ;~ ;~ Select ;~ case _IsPressed("01", $dll) and Stringinstr($a,"Edit",2)>0 and $pos[1] > 55 and Stringinstr($a,"COMBO",2)=0 ;~ MouseClick("left") ;~ ;ToolTip("Object:" & $a,$pos[0], $pos[1]) ;~ ;~ case _IsPressed("01", $dll) and Stringinstr($a,"Spread1",2)>0 and $pos[1] > 55 and Stringinstr($a,"COMBO",2)=0 ;~ MouseClick("left") ;~ case _IsPressed("02", $dll) and Stringinstr($a,"unipict",2)>0 and controlcommand("Oazis","","UniCanvas1","IsVisible", "")=1 and controlcommand("Oazis","","UniCanvas2","IsVisible", "")<>1 and $pos[1] > 55 and Stringinstr($a,"COMBO",2)=0 ;~ ;als er geen icoon aanwezig = ook geen quicky ;~ if $color<>"00C6C3C6" Then ;~ create_menu(MouseGetPos(),ControlGetText("Oazis", "", "Edit188")) ;~ endif ;~ endselect ;~ ;~ EndIf Select case $a="OwiCmdButton17" and $wintext=0 ;patientinfo $patid=ControlGetText("Oazis", "", "Edit27") $patnaam = ControlGetText("Oazis", "", "Edit23") & " " & ControlGetText("Oazis", "", "Edit22") $huisarts = ControlGetText("Oazis", "", "Edit4") $print="N" $taal=stringleft(ControlGetText("Oazis", "", "Edit37"),1) sleep(100) ;indien men te lang de knop zou in houden ControlClick("Oazis", "", $a) msg_informed_consent($huisarts,$patnaam,$oazis_user,$osuser,$workstation,$patid,$print,$taal) EndSelect ;low cpu gebruik sleep(50) WEnd ;Hook terug vrijgeven DllCall("user32.dll", "int", "UnhookWindowsHookEx", "hwnd", $hHook[0]) DllCallbackFree($hKeyProc) ;DllClose($dll) Exit func msg_informed_consent($huisarts,$patnaam,$oazis_user,$osuser,$workstation,$patid,$print,$taal) if $huisarts<>"" and $patnaam<>"" then if Stringinstr($huisarts,"onbekend",2)=0 then ;Sleep(100) $res=msgbox(262179,"Afdrukken toestemmingsformulier","Geeft de patiënt, " & $patnaam & ", zijn akkoord tot inzage van zijn medisch dosssier door zijn huisarts, dr. " &$huisarts& "?"&Chr(13)&get_historiek("",$patid)) if $res=6 Then ;ja $cmd="C:\Program Files\Afdruk Toestemmingsformulier Huisarts\AfdrukContractHP.exe" $cmd=$cmd & " /pat_id:"&$patid&" /doctor_home_access:Y /cr_who:"&$oazis_user&" /cr_os_user:"&$osuser&" /cr_terminal:" & $workstation & " /force_printer:" & $print & " /language:" & $taal; & " /Force_message:Y" Run($cmd,"", @SW_MINIMIZE) Else if $res=7 Then ;nee $cmd="C:\Program Files\Afdruk Toestemmingsformulier Huisarts\AfdrukContractHP.exe" $cmd=$cmd & " /pat_id:"&$patid&" /doctor_home_access:N /cr_who:"&$oazis_user&" /cr_os_user:"&$osuser&" /cr_terminal:" & $workstation & " /force_printer:" & $print & " /language:" & $taal;& " /Force_message:Y" Run($cmd,"", @SW_MINIMIZE) endif EndIf Else sleep(500) ;huisarts onbekend $res=msgbox(262452,"Huisarts onbekend","Bevestig u dat de huisarts onbekend is voor de patiënt, " & $patnaam &"?" ) if $res=6 Then ;voorlopig niets uitvoeren Else ;nee ControlClick("Oazis", "", "OwiCmdButton8") EndIf endif endif endfunc Func get_patinfo($patid) $tsn_name = "OAZP" $userid="OAZIS" $password = "123" $sql_code="select replace(a.lastname,' ','')||' '||replace(a.firstname,' ','') patient,replace(d.name,' ','')||' '||replace(d.first_name,' ','') huisarts " $sql_code=$sql_code & ",decode(replace(pat_language,' ',''),'F','F','NL','N','USA','E',replace(pat_language,' ','')) taal " $sql_code=$sql_code & "from adt_unipat a, doctors d " $sql_code=$sql_code & "where a.DOCTOR_ID_HOME=d.UNI_PERS_NO and a.pat_id='"&$patid&"'" $ORA_CONN = ObjCreate("ADODB.Connection") $ORA_CONN.Open("Driver={Microsoft ODBC for Oracle};Server=" & $tsn_name & ";Uid="& $userid & ";Pwd=" & $password & ";") $RST = ObjCreate("ADODB.Recordset") $RST.Open($sql_code, $ORA_CONN) if not $RST.eof then $array = $RST.GetRows() Else $array="" endif $RST.Close $RST = 0 Return $array EndFunc Func get_historiek($historiek,$patid) $tsn_name = "OAZP" $userid="OAZIS" $password = "123" $sql_code = "select to_char(cr_date,'dd/MM/yyyy hh24:mi') cr_date, replace(cr_who,' ','') cr_who, decode(replace(doctor_home_access,' ',''),'N','GEEN TOEGANG','Y','TOEGANG') doctor_home_access " $sql_code = $sql_code & "from adt_unipat_doc_home_access " $sql_code = $sql_code & "where pat_id='"&$patid&"' and cr_date=(select max(cr_date) from adt_unipat_doc_home_access where pat_id='"&$patid&"')" $ORA_CONN = ObjCreate("ADODB.Connection") $ORA_CONN.Open("Driver={Microsoft ODBC for Oracle};Server=" & $tsn_name & ";Uid="& $userid & ";Pwd=" & $password & ";") $RST = ObjCreate("ADODB.Recordset") $RST.Open($sql_code, $ORA_CONN) if not $RST.eof then $array = $RST.GetRows() ;$historiek="Laatste validatie:" & $array[0][1] & " - " & $array[0][2] & " - " & $array[0][3] $historiek="Laatste informed consent werd geregistreerd op " & $array[0][0] & " door " & $array[0][1] & " met als resultaat:" & $array[0][2] & "." Else $historiek="Geen validatie info beschikbaar." endif $RST.Close $RST = 0 Return $historiek EndFunc Func create_menu($pos,$patid) Local $widthCell, $msg GUICreate("Oazis Quicky", 185, 56, $pos[0],$pos[1],"",$WS_EX_TOPMOST+$WS_EX_TOOLWINDOW) $iOldOpt = Opt("GUICoordMode", 0) $Button_1 = GUICtrlCreateButton("Informed consent afdrukken", 2, 2, 32,32,$BS_ICON) GUICtrlSetImage($Button_1, "shell32.dll", 22,0) $Label_1 = GUICtrlCreateLabel("Informed consent afdrukken", 40, 10) GUICtrlSetTip($Button_1,get_historiek("",$patid)) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Button_1 ;algemene info $oazis_user=$CmdLine[1] $workstation = @ComputerName $osuser = "kl_groeninghe\"&@UserName ;patientinfo $array=get_patinfo($patid) if $array<>"" then $patnaam = $array[0][0] $huisarts = $array[0][1] $print="Y" $taal=$array[0][2] if Stringinstr($huisarts,"onbekend",2)=0 then msg_informed_consent($huisarts,$patnaam,$oazis_user,$osuser,$workstation,$patid,$print,$taal) Else $res=msgbox(262180,"Huisarts onbekend", "Huisarts onbekend, gelieve deze te bevragen en aan te vullen.") endif endif ExitLoop EndSelect WEnd GUIDelete() EndFunc Func _Mouse_Handler($nCode, $wParam, $lParam) If $nCode < 0 Then Local $aRet = DllCall("user32.dll", "long", "CallNextHookEx", "hwnd", $hHook[0], "int", $nCode, "wparam", $wParam, _ "lparam", $lParam) Return $aRet[0] EndIf Switch BitAND($WParam, 0xFFFF) Case 513;Primary Down _CheckInterval() EndSwitch EndFunc Func _CheckInterval() If $Timer = 0 Then $Timer = TimerInit() Else If TimerDiff($Timer) <= 500 Then ;simuleren van dblclick door snelheid van script MouseClick("left") MouseClick("left") $Timer = TimerInit() endif EndIf EndFunc Link to comment Share on other sites More sharing options...
rasim Posted August 19, 2008 Share Posted August 19, 2008 KmeerschForks fine for me:expandcollapse popupHotKeySet("{Esc}", "_Exit") Global Const $WH_MOUSE_LL = 14 Global $DblClk_Speed = RegRead("HKCU\Control Panel\Mouse", "DoubleClickSpeed") ;Getting system double click speed If @error Then $DblClk_Speed = 500 Global $Timer = 0 Global $hKeyProc = DllCallbackRegister ("_Mouse_Handler", "int", "int;ptr;ptr") Global $hmod = DllCall("kernel32.dll", "hwnd", "GetModuleHandle", "ptr", 0) Global $hHook = DllCall("user32.dll", "hwnd", "SetWindowsHookEx", "int", $WH_MOUSE_LL, _ "ptr", DllCallbackGetPtr($hKeyProc), "hwnd", $hmod[0], "dword", 0) Run("notepad.exe", "", @SW_MINIMIZE) WinWait("[Class:Notepad]") $hWndNotepad = WinGetHandle("[Class:Notepad]") While WinExists($hWndNotepad) $iFocus = ControlGetFocus($hWndNotepad) Sleep(100) WEnd Func _Mouse_Handler($nCode, $wParam, $lParam) If $nCode < 0 Then Local $aRet = DllCall("user32.dll", "long", "CallNextHookEx", "hwnd", $hHook[0], "int", $nCode, "wparam", $wParam, _ "lparam", $lParam) Return $aRet[0] EndIf Switch BitAND($WParam, 0xFFFF) Case 513 ;Primary Down _CheckInterval() EndSwitch EndFunc Func _CheckInterval() If $Timer = 0 Then $Timer = TimerInit() Else If TimerDiff($Timer) <= 500 Then ConsoleWrite("!> Double click" & @LF) $Timer = TimerInit() EndIf EndFunc Func _Exit() DllCall("user32.dll", "int", "UnhookWindowsHookEx", "hwnd", $hHook[0]) DllCallbackFree($hKeyProc) Exit EndFunc Link to comment Share on other sites More sharing options...
Kmeersch Posted August 19, 2008 Author Share Posted August 19, 2008 What I'm missing? When I type the "consolewrite" function on the same line, it works ... I just changed the following code: Func _CheckInterval() If $Timer = 0 Then $Timer = TimerInit() Else [b]If (TimerDiff($Timer) <= 500) Then ConsoleWrite("dd"& @LF) $Timer = TimerInit() EndIf [/b] EndIf EndFunc Link to comment Share on other sites More sharing options...
MarcoM Posted August 25, 2008 Share Posted August 25, 2008 When i use the function getcontrolfocus(), the script detects no more DBLClick. I have the same problem. When I'm writing a loop to test if the focus is set on a particular control, it kills double-clicking: While 1 $CurrentWin = WinGetHandle("[Active]") $CurrentControl = ControlGetFocus ($CurrentWin) Sleep(50) Wend Do you think it's a bug of ControlGetFocus () function? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now