Sign in to follow this  
Followers 0
FireFox

Problem with combo box... (autoit problem i think...)

5 posts in this topic

#1 ·  Posted (edited)

Hi,

I've made script for count keys pressed by user, you can select if you want script to count for keyboard, mouse, keyboard and mouse

But the combo don't work for keyboard only because script doesnt detect combo is one "keyboard"...

#include <Constants.au3>
#include <DllCallBack.au3>
#include <GuiConstants.au3>
#include <WindowsConstants.au3>
#include <ComboConstants.au3>
#include <Misc.au3>

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

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

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

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

#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
Local $GUIlblDateStarted, $GUIlblKeysPressed
Global $Countwhat = 0
Global $TotalKey = 0
_ReduceMemory(@ScriptName)
#EndRegion

#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("Total keys pressed :", 5, 25, 100, 15)
$GUIlblKeysPressed = GUICtrlCreateLabel("0", 105, 25, 100, 15)
GUICtrlCreateLabel("Count key of :", 170, 5)
$GUIcboKeyMouse = GUICtrlCreateCombo("All", 240, 2, 80, 17, $CBS_DROPDOWNLIST)
GUICtrlSetData(-1, "Mouse|Keyboard", "All")
GUISetState(@SW_SHOW)
#EndRegion

While 1
    Sleep(50)
    If (GUICtrlRead($GUIcboKeyMouse) = "All") Then
        If Not $Countwhat = 0 Then
            Global $Countwhat = 0
        EndIf
    ElseIf (GUICtrlRead($GUIcboKeyMouse) = "Mouse") Then
        If Not $Countwhat = 1 Then
            Global $Countwhat = 1
        EndIf
    ElseIf (GUICtrlRead($GUIcboKeyMouse) = "Keyboard") Then
        If Not $Countwhat = 2 Then
            Global $Countwhat = 2
        EndIf
    EndIf
    
    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

    TraySetToolTip("Keys pressed : "&$TotalKey)
WEnd


Func _CLOSE()
    GUISetState(@SW_HIDE,$GUI)
EndFunc

Func _SHOW()
    GUISetState(@SW_SHOW,$GUI)
EndFunc

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()
    DllCall("user32.dll", "int", "UnhookWindowsHookEx", "hwnd", $hHook[0])
    Exit
EndFunc;==>OnAutoItExit

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 for anyhelp :)

Edited by FireFox

 

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



I can see nothing wrong with your code ...

You can replace the whole If-ElseIf thing with a Select or a Switch and see what you get.

Personally I avoid using If-ElseIf as much as possible, Select or Switch seem to be more appropriate for this job.


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

@enaiman

Well, i don't like switch and case etc...but if that would work... I will try it so :)

I don't like when there are no error in your script and that don't work :)


 

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

I don't like when there are no error in your script and that don't work :)

There are errors, some are just harder to see than others.
If Not $Countwhat = 0 Then

is not the same as:

If $Countwhat <> 0

But, since that comparison isn't actually doing anything, there's no harm in resetting the variable in each iteration.

Replace your If block with this:

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

[font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font]

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

There are errors, some are just harder to see than others.

If Not $Countwhat = 0 Then

is not the same as:

If $Countwhat <> 0

But, since that comparison isn't actually doing anything, there's no harm in resetting the variable in each iteration.

Replace your If block with this:

Switch GUICtrlRead($GUIcboKeyMouse)
        Case "All"
            $Countwhat = 0
        Case "Mouse"
            $Countwhat = 1
        Case "Keyboard"
            $Countwhat = 2
    EndSwitch
Ok, thanks it works Edited by FireFox

 

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