Jump to content

Key Counter Issues


Recommended Posts

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...