TriCk Posted June 12, 2013 Posted June 12, 2013 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. expandcollapse popup#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.
FireFox Posted June 12, 2013 Posted June 12, 2013 (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 June 12, 2013 by Melba23 Removed link
TriCk Posted June 12, 2013 Author Posted June 12, 2013 (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: 288I also got an error with the "What you've done today" program you wrote. Edited June 12, 2013 by Melba23 Removed link in quote
FireFox Posted June 12, 2013 Posted June 12, 2013 Yeah, old stuff. Hence the errors. For the _IsPressed UDF remove the _IsPressed function inside and for the project try to fix it yourself
Keniger Posted June 12, 2013 Posted June 12, 2013 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
Moderators Melba23 Posted June 12, 2013 Moderators Posted June 12, 2013 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. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Recommended Posts