Sign in to follow this  
Followers 0
TriCk

Key Counter Issues

6 posts in this topic

Hello, I am creating a key counter for a friend to measure actions per second, I've been stuck on this for quite some time and have been looking for some solutions.

 

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>

global $mouseCount
global $keyCount
global $isEnabled
global $timeEnabled
global $roundedKey
global $roundedMouse
global $roundedTotal
global $Label1


ShowGUI()
TimeEnabled()

while 1
    global $dll = DllOpen("user32.dll")
    if _IsPressed("01", $dll) or _IsPressed("02", $dll) then CountMouse()
    if _IsPressed("41", $dll) or _IsPressed("42", $dll) or _IsPressed("43", $dll) or _IsPressed("44", $dll) or _IsPressed("45", $dll) or _IsPressed("46", $dll) or _IsPressed("47", $dll) or _IsPressed("48", $dll) or _IsPressed("49", $dll) or _IsPressed("4A", $dll) or _IsPressed("4B", $dll) or _IsPressed("4C", $dll) or _IsPressed("4D", $dll) or _IsPressed("4E", $dll) or _IsPressed("4F", $dll) or _IsPressed("50", $dll) or _IsPressed("51", $dll) or _IsPressed("52", $dll) or _IsPressed("53", $dll) or _IsPressed("54", $dll) or _IsPressed("55", $dll) or _IsPressed("56", $dll) or _IsPressed("57", $dll) or _IsPressed("58", $dll) or _IsPressed("59", $dll) or _IsPressed("5A", $dll) then CountKey()
WEnd


Func Enabled()
    if $isEnabled = 0 Then
        $isEnabled = 1
        TimeEnabled()
    else
        $isEnabled = 0
    EndIf
EndFunc

Func TimeEnabled()
    Sleep(1000)
    $timeEnabled = $timeEnabled + 1
    TimeEnabled()
    Average()
EndFunc

Func CountKey()

    if $isEnabled = 1 Then
        $keyCount = $keyCount + 1
    EndIf
EndFunc

Func CountMouse()
    if $isEnabled = 1 Then
        $mouseCount = $mouseCount + 1
    EndIf
EndFunc

Func Average()
    $keyAverage = $timeEnabled / $keyCount
    $mouseAverage = $timeEnabled / $mouseCount
    $totalAverage = ($keyCount + $mouseCount) / $timeEnabled
    $roundedKey = Round($keyAverage,0)
    $roundedMouse = Round($mouseAverage,0)
    $roundedTotal = Round($totalAverage,0)
GUICtrlSetData($Label1, "KPS: " & $roundedKey & "  MPS: " & $roundedMouse & "   TPS: " & $roundedTotal)
EndFunc

Func ShowGUI()

    $Form1 = GUICreate("Key Counter by AlwaysUltra", 201, 101, 192, 124, -1, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW), 0)
    GUISetBkColor(0xC0C0C0)
    GUICtrlSetFont(-1, 10, 600, 0, "Segoe UI")
    GUICtrlSetColor(-1, 0xFF0000)
    $Label1 = GUICtrlCreateLabel("KPS: "&$roundedKey&"  MPS: "& $roundedMouse & "  TPS: " &$roundedTotal, 0, 8, 196, 17)
    $Button1 = GUICtrlCreateButton("Toggle", 0, 72, 75, 25)
    $Button2 = GUICtrlCreateButton("Exit", 120, 72, 75, 25)
    GUISetState(@SW_SHOW)


    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $Button2
                Exit
            Case $Button1
                Enabled()
        EndSwitch
    WEnd

EndFunc

I tried switching up the function enabled by calling TimeEnabled() at the beginning of the program, but that didn't seem to work either. Thank you so much for reading over this, I appreciate it.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hi,

Take a look at my _IsPressedUDF (link in my signature) and use the _IsAnyKeyPressed function.

#include "IsPressed_UDF.au3"
 
Local $hTimer = TimerInit(), $iKeyCount = 0
 
While 1
    If TimerDiff($hTimer) >= 1000 Then
        ConsoleWrite($iKeyCount & @CrLf)
        $hTimer = TimerInit()
        $iKeyCount = 0
    EndIf
 
    If _IsAnyKeyPressed() = 1 Then
        $iKeyCount += 1
    EndIf
WEnd
 

Br, FireFox.

Edited by Melba23
Removed link

 

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

#3 ·  Posted (edited)

Hi,

Take a look at my _IsPressedUDF (link in my signature) and use the _IsAnyKeyPressed function.

#include "IsPressed_UDF.au3"
 
Local $hTimer = TimerInit(), $iKeyCount = 0
 
While 1
    If TimerDiff($hTimer) >= 1000 Then
        ConsoleWrite($iKeyCount & @CrLf)
        $hTimer = TimerInit()
        $iKeyCount = 0
    EndIf
 
    If _IsAnyKeyPressed() = 1 Then
        $iKeyCount += 1
    EndIf
WEnd
 

Br, FireFox.

It says Func _IsPressed($sHexKey, $vDLL = 'user32.dll') ERROR: _IsPressed() already defined from the file IsPressed_UDF. LINE: 288

I also got an error with the "What you've done today" program you wrote.

Edited by Melba23
Removed link in quote

Share this post


Link to post
Share on other sites

Yeah, old stuff. Hence the errors.

For the _IsPressed UDF remove the _IsPressed function inside and for the project try to fix it yourself ;)


 

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

Look :

_WinApi_GetAsyncKeyState() For keyboard

Simple loop :

For 1 to 50

Winapi blabablabla...

If u know what I mean, I cant give u code coz this function is connected with keylogger :D

Share this post


Link to post
Share on other sites

TriCk,

I am afraid that what you are doing is too close to a keylogger for my liking. Even if this is not your intention, the capability is there. Thread locked. :naughty:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  
Followers 0