Sign in to follow this  
Followers 0
FireFox

Script always have problems when I add something...

1 post in this topic

Hi,

I've added to my script record function but this doesnt work for example when total keys is highter than record, the data of label doesnt change or sometimes it works...

And when exit I want script to save record If keys are highter than last record, but it doesnt want to....

See notes in the script for help me :)

#Region Start-up
;~ RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "KeyCounter", "REG_SZ", @ScriptFullPath)
#EndRegion Start-up

#Region Opt
Opt("TrayMenuMode", 1)
Opt("TrayOnEventMode", 1)
Opt("GuiOnEventMode", 1)
#EndRegion Opt

#Region Tray
TraySetIcon("Shell32.dll", 27)

TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "_Exit")
TraySetOnEvent(-13, "_SHOW")
#EndRegion Tray

#Region Hook Keyboard
Global Const $WH_KEYBOARD_LL = 13
Global $hHook, $pStub_KeyProc
Global $pStub_KeyProc = _DllCallBack("_KeyProc", "int;ptr;ptr")
Global $hmod = DllCall("kernel32.dll", "hwnd", "GetModuleHandle", "ptr", 0)
Global $hHook = DllCall("user32.dll", "hwnd", "SetWindowsHookEx", "int", $WH_KEYBOARD_LL, "ptr", $pStub_KeyProc, "hwnd", $hmod[0], "dword", 0)
Global $buffer = ""
Global $KeyCount
#EndRegion Hook Keyboard

#Region Variables
$Record = FileRead(@TempDir & "\KeyCounter.txt")
Local $GUIlblDateStarted, $GUIlblKeysPressed
Global $Countwhat = 0
Global $TotalKey = 0
_ReduceMemory(@ScriptName)
#EndRegion Variables

#Region GUI
$GUI = GUICreate("Key counter", 330, 45, -1, -1, -1, BitOR($WS_EX_APPWINDOW, $WS_EX_TOOLWINDOW, $WS_EX_TOPMOST))
GUISetOnEvent($GUI_EVENT_CLOSE, "_CLOSE")
GUICtrlCreateLabel("Date started :", 5, 5, 70, 15)
$GUIlblDateStarted = GUICtrlCreateLabel(@MDAY & "/" & @MON & "/" & @YEAR, 75, 5, 150, 15)
GUICtrlCreateLabel("Keys pressed :", 5, 27, 100, 15)
$GUIlblKeysPressed = GUICtrlCreateLabel("0", 80, 27, 100, 15)
GUICtrlCreateLabel("Count key of :", 170, 5)
$GUIcboKeyMouse = GUICtrlCreateCombo("All", 240, 2, 80, 17, $CBS_DROPDOWNLIST)
GUICtrlSetData(-1, "Mouse|Keyboard", "All")
GUICtrlCreateLabel("Record :", 195, 27)
$GUIlblRecord = GUICtrlCreateLabel(FileRead(@TempDir & "\KeyCounter.txt"), 245, 27, 100)
GUISetState(@SW_HIDE)
#EndRegion GUI

While 1
    Sleep(50)
    Switch GUICtrlRead($GUIcboKeyMouse)
        Case "All"
            $Countwhat = 0
        Case "Mouse"
            $Countwhat = 1
        Case "Keyboard"
            $Countwhat = 2
    EndSwitch

    If $Countwhat = 1 Or $Countwhat = 0 Then
        If _IsPressed("01") _
                Or _IsPressed("02") _
                Or _IsPressed("04") _
                Or _IsPressed("05") _
                Or _IsPressed("06") Then
            Do
                Sleep(50)
            Until Not _IsPressed("01") _
                    Or _IsPressed("02") _
                    Or _IsPressed("04") _
                    Or _IsPressed("05") _
                    Or _IsPressed("06")
            GUICtrlSetData($GUIlblKeysPressed, $TotalKey + 1)
            Global $TotalKey = GUICtrlRead($GUIlblKeysPressed)
        EndIf
    EndIf

    If $TotalKey > $Record Then;This works when it wants....
        GUICtrlSetData($GUIlblRecord, $TotalKey)
    EndIf
    TraySetToolTip("Keys pressed : " & $TotalKey)
WEnd


Func _CLOSE()
    GUISetState(@SW_HIDE, $GUI)
EndFunc  ;==>_CLOSE

Func _SHOW()
    GUISetState(@SW_SHOW, $GUI)
EndFunc  ;==>_SHOW

Func EvaluateKey($keycode)
    If (($keycode > 22) And ($keycode < 91)) _
            Or (($keycode > 47) And ($keycode < 58)) Then
        GUICtrlSetData($GUIlblKeysPressed, $TotalKey + 1)
        Global $TotalKey = GUICtrlRead($GUIlblKeysPressed)
    Else
        GUICtrlSetData($GUIlblKeysPressed, $TotalKey + 1)
        Global $TotalKey = GUICtrlRead($GUIlblKeysPressed)
    EndIf
EndFunc  ;==>EvaluateKey

Func _KeyProc($nCode, $wParam, $lParam)
    Local $ret, $KEYHOOKSTRUCT
    
    If $Countwhat = 0 Or $Countwhat = 2 Then
        If $nCode < 0 Then
            $ret = DllCall("user32.dll", "long", "CallNextHookEx", "hwnd", $hHook[0], _
                    "int", $nCode, "ptr", $wParam, "ptr", $lParam)
            Return $ret[0]
        EndIf
        If $wParam = 256 Then
            $KEYHOOKSTRUCT = DllStructCreate("dword;dword;dword;dword;ptr", $lParam)
            EvaluateKey(DllStructGetData($KEYHOOKSTRUCT, 1))
        EndIf
        $ret = DllCall("user32.dll", "long", "CallNextHookEx", "hwnd", $hHook[0], _
                "int", $nCode, "ptr", $wParam, "ptr", $lParam)
        Return $ret[0]
    EndIf
EndFunc  ;==>_KeyProc

Func _Exit()
    MsgBox(64,"",$Record&" | "&$TotalKey);Here you can see that Record is under TotalKey...
    If $Record < $TotalKey Then;But this dont work
        MsgBox(64,"","");Msgbox doesnt appears.......
        FileDelete(@TempDir & "\KeyCounter.txt")
        FileWrite(@TempDir & "\KeyCounter.txt", $TotalKey)
    EndIf
    DllCall("user32.dll", "int", "UnhookWindowsHookEx", "hwnd", $hHook[0])
    Exit
EndFunc  ;==>_Exit

Func _ReduceMemory($i_PID = -1)
    If $i_PID <> -1 Then
        Local $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $i_PID)
        Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle[0])
        DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle[0])
    Else
        Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1)
    EndIf

    Return $ai_Return[0]
EndFunc  ;==>_ReduceMemory

Thanks.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
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
Sign in to follow this  
Followers 0