Что нового

Отследить нажатие кнопки

Kislyak217

Новичок
Сообщения
4
Репутация
0
Всем привет,
Я сделал програмку котороя считает сколько я отправил заявок, ниже скрин:

imgpsh_fullsize_anim (1).png

Программа считает по нажатию кнопки Проверен:

imgpsh_fullsize_anim.png

Ниже код:

Код:
#NoTrayIcon

Global Const $WH_MOUSE_LL                     = 14
Global Const $MOUSE_PRIMARYDOWN_EVENT        = 513
Global Const $MOUSE_PRIMARYUP_EVENT            = 514

Global $hCtrlEvent_CallBack                 = 0
Global $hCtrlEvent_MHook                     = 0

Global $aCtrlEvents[1][1]

Func _WinControlSetEvent($hWindow, $nCtrlID, $sCallOnHoldFunc, $sOnHoldParams="", $sCallOnReleaseFunc="", $sOnReleaseParams="")
    If $aCtrlEvents[0][0] = 0 Then
        $hCtrlEvent_CallBack = DllCallbackRegister("_WinCtrlEvents_Handler", "int", "int;ptr;ptr")

        Local $hM_Module = DllCall("Kernel32.dll", "hwnd", "GetModuleHandle", "ptr", 0)
        Local $hM_Hook = DllCall("User32.dll", "hwnd", "SetWindowsHookEx", "int", $WH_MOUSE_LL, _
            "ptr", DllCallbackGetPtr($hCtrlEvent_CallBack), "hwnd", $hM_Module[0], "dword", 0)

        $hCtrlEvent_MHook = $hM_Hook[0]
    EndIf

    $aCtrlEvents[0][0] += 1
    ReDim $aCtrlEvents[$aCtrlEvents[0][0]+1][6]

    $aCtrlEvents[$aCtrlEvents[0][0]][0] = $hWindow
    $aCtrlEvents[$aCtrlEvents[0][0]][1] = $nCtrlID
    $aCtrlEvents[$aCtrlEvents[0][0]][2] = $sCallOnHoldFunc
    $aCtrlEvents[$aCtrlEvents[0][0]][3] = $sOnHoldParams
    $aCtrlEvents[$aCtrlEvents[0][0]][4] = $sCallOnReleaseFunc
    $aCtrlEvents[$aCtrlEvents[0][0]][5] = $sOnReleaseParams

    Return 1
EndFunc

Func _WinCtrlEvents_Handler($nCode, $wParam, $lParam)
    Local $iEvent = BitAND($wParam, 0xFFFF)

    If $iEvent = $MOUSE_PRIMARYUP_EVENT Or $iEvent = $MOUSE_PRIMARYDOWN_EVENT Then
        Local $hWindow = _WinGetHoveredHandle()
        Local $aCtrlID = _ControlGetHoveredID()

        Local $sCtrlData = ControlGetText($hWindow, "", $aCtrlID[1])

        For $i = 1 To $aCtrlEvents[0][0]
            If ($aCtrlEvents[$i][0] = $hWindow Or WinGetHandle($aCtrlEvents[$i][0]) = $hWindow) And ($aCtrlID[1] <> 0 And _
                ($aCtrlEvents[$i][1] = $aCtrlID[1] Or $aCtrlEvents[$i][1] = $sCtrlData Or _
                    $aCtrlEvents[$i][1] = _WinGetClassNameNN($aCtrlID[1], $hWindow))) Then

                If $iEvent = $MOUSE_PRIMARYDOWN_EVENT Then
                    Call($aCtrlEvents[$i][2], $aCtrlEvents[$i][3], $hWindow, $aCtrlID[1])
                    If @error Then Call($aCtrlEvents[$i][2], $aCtrlEvents[$i][3], $hWindow)
                    If @error Then Call($aCtrlEvents[$i][2], $aCtrlEvents[$i][3])
                    If @error Then Call($aCtrlEvents[$i][2])
                ElseIf $iEvent = $MOUSE_PRIMARYUP_EVENT Then
                    Call($aCtrlEvents[$i][4], $aCtrlEvents[$i][5], $hWindow, $aCtrlID[1])
                    If @error Then Call($aCtrlEvents[$i][4], $aCtrlEvents[$i][5], $hWindow)
                    If @error Then Call($aCtrlEvents[$i][4], $aCtrlEvents[$i][5])
                    If @error Then Call($aCtrlEvents[$i][4])
                EndIf

                ExitLoop
            EndIf
        Next
    EndIf
EndFunc

Func _ControlGetHoveredID()
    Local $aRet[2]
    Local $iOld_Opt_MCM = Opt("MouseCoordMode", 1)

    Local $hRet = DllCall("user32.dll", "int", "WindowFromPoint", "long", MouseGetPos(0), "long", MouseGetPos(1))

    $aRet[0] = $hRet[0]

    $hRet = DllCall("user32.dll", "int", "GetDlgCtrlID", "hwnd", $hRet[0])
    If $hRet[0] < 0 Then $hRet[0] = 0

    Opt("MouseCoordMode", $iOld_Opt_MCM)

    $aRet[1] = $hRet[0]

    Return $aRet
EndFunc

Func _WinGetHoveredHandle()
    Local $iOld_Opt_MCM = Opt("MouseCoordMode", 1)
    Local $aRet = DllCall("user32.dll", "int", "WindowFromPoint", "long", MouseGetPos(0), "long", MouseGetPos(1))

    Opt("MouseCoordMode", $iOld_Opt_MCM)

    $aRet = DllCall("User32.dll", "hwnd", "GetAncestor", "hwnd", $aRet[0], "uint", 2) ;$GA_ROOT

    Return HWnd($aRet[0])
EndFunc

Func _WinGetClassNameNN($hCtrlWnd, $hWinWnd="")
    $hCtrlWnd = ControlGetHandle($hWinWnd, "", $hCtrlWnd)
    $sClassName = _WinGetClassName($hCtrlWnd)
    $aClassList = StringSplit(WinGetClassList($hWinWnd), @CRLF)

    For $iC In $aClassList
        If $iC = $sClassName Then
            For $j = 1 To UBound($aClassList)
                If ControlGetHandle($hWinWnd, "", $iC & $j) = $hCtrlWnd Then Return $iC & $j
            Next
        EndIf
    Next

    Return $sClassName
EndFunc

Func _WinGetClassName($hWnd)
    Local $aClassName = DLLCall("user32.dll", "int", "GetClassName", "hWnd", $hWnd, "str", "", "int", 256)

    If Not @error And $aClassName[0] <> 0 Then Return $aClassName[2]
    Return @error
EndFunc

Func _OnAutoItExit()
    If IsArray($hCtrlEvent_MHook) And $hCtrlEvent_MHook[0] > 0 Then
        DllCall("User32.dll", "int", "UnhookWindowsHookEx", "hwnd", $hCtrlEvent_MHook[0])
        $hCtrlEvent_MHook[0] = 0
    EndIf

    If IsPtr($hCtrlEvent_CallBack) Then
        DllCallbackFree($hCtrlEvent_CallBack)
        $hCtrlEvent_CallBack = 0
    EndIf
EndFunc

HotKeySet("{F1}", "_deldiacritics")
HotKeySet("{`}","_winactiv")
HotKeySet("{F2}","_winactiv2")
HotKeySet("{F3}","_checkmsg")
HotKeySet("{F6}","_hwnd")
HotKeySet("{F10}", "_close")

Global $true1 = False
Local $i = 0

$iGetCalcResults = False

_WinControlSetEvent("Заказ", "Проверен", "", "", "CalcGetResult_Proc")

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("Terrasoft+", 143, 123, -1, -1, -1, BitOR($WS_EX_TOOLWINDOW,$WS_EX_WINDOWEDGE))
$Label12 = GUICtrlCreateLabel("_________________________________________________________________________", -8, -112, 2997, 132)
GUICtrlSetFont(-1, 72, 800, 0, "@Malgun Gothic")
GUICtrlSetColor(-1, 0xFF0000)
$label = GUICtrlCreateLabel("F1 - Del diacritic", 24, 12, 85, 17)
$label01 = GUICtrlCreateLabel("F2 - Open Skype", 24, 28, 85, 17)
$label03 = GUICtrlCreateLabel("`  - Open Chrome", 24, 44, 85, 17)
$label04 = GUICtrlCreateLabel("F6 - Hide/Show", 24, 60, 85, 17)
$Label1 = GUICtrlCreateLabel("F10 - Close", 24, 76, 57, 17)
$Label2 = GUICtrlCreateLabel("Проверенно:", 8, 98, 82, 17)
$Label3 = GUICtrlCreateLabel($i, 90, 98, 100, 37)
GUICtrlSetColor(-1, 0xFF0000)
GUISetState(@SW_SHOW)
WinSetOnTop($Form1, '', 1)


While 1
$nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
         EndSwitch
         Sleep(10)
    _check()
 WEnd

Func _check()
      ;Start Statistic
         If $iGetCalcResults <> False Then
        $iParam = $iGetCalcResults
        $iGetCalcResults = False

        $sCtrl_Data = ControlGetText("Заказ", "", $iParam)

        If $sCtrl_Data = "=" Then
            Local $sResult = StringStripWS(ControlGetText("Заказ", "", "Проверен"), 3)
            If StringRight($sResult, 1) = "," Then $sResult = StringTrimRight($sResult, 1)

        ElseIf $sCtrl_Data <> "" Then
            $i = $i + 1
GUICtrlSetData($Label3, $i)
      EndIf
   EndIf
    ;EndStatistic
   EndFunc

Func _checkmsg()
   MsgBox(0, "Проверенно заказов", $i)
EndFunc

Func _hwnd()
Switch @HotKeyPressed
        Case "{F6}"
            $true1 = NOT $true1
            If $true1 = True Then
             GUISetState(@SW_HIDE)
             Else
             GUISetState(@SW_SHOW)
            EndIf
    EndSwitch
EndFunc

Func _deldiacritics()
Send("^{c}")
Sleep(10)
Local $sData = ClipGet()
ClipPut(BinaryToString(StringToBinary($sData)))
Send("^{v}")
EndFunc

Func _winactiv()
Opt("WintitleMatchMode", 2)
WinActivate("Google Chrome")
EndFunc

Func _winactiv2()
Opt("WintitleMatchMode", 2)
WinActivate("Skype")
EndFunc

Func CalcGetResult_Proc($sParams, $hWnd, $nCtrlID)
    $iGetCalcResults = $nCtrlID
EndFunc

Func _close()
   Exit
EndFunc


Есть большое НО, Виснет система и сам скрипт потом останавливается.

Нужна помощь, либо как то сделать чтоб не глючило и чтоб скрипт не остановился, либо есть другие варианты как подсчитать кол-во проверенных заявок.
 
Последнее редактирование:
Верх