AutoHotkey Community

It is currently May 27th, 2012, 10:45 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 11 posts ] 
Author Message
PostPosted: March 22nd, 2005, 6:33 pm 
Offline

Joined: February 26th, 2005, 5:36 am
Posts: 21
OK - been searching for a while and haven't found anything yet so will pose it here as a question.

I theoretically figured I could possibly map every key and mouse piece etc to call a count method before passing through to whatever they normally do, but asside from that idea is there an easier way to count the keystrokes/mouse movements and clicks?

I am writing a piece of software and I want to show the significant savings of keystrokes/usage etc if possible.

Thanks - and great scripting tool here Chris - much much appreciated.

V.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 22nd, 2005, 6:57 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
AutoHotkey Documentation wrote:
( ~ ) This hotkey's native function shouldn't be suppressed (hidden from the system) when the hotkey fires.

If you do something like:
Code:
~a::
~b::
~c::
;... keep doing same through all characters
KeyCount += 1
Return

;Ctrl+S to show click count #
^s::MsgBox, Count: %KeyCount%
Return

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 22nd, 2005, 7:04 pm 
Offline

Joined: March 20th, 2005, 5:33 pm
Posts: 17
Here is a simpler way. (Made with excel)
Code:
~SC001::
~SC002::
~SC003::
~SC004::
~SC005::
~SC006::
~SC007::
~SC008::
~SC009::
~SC00a::
~SC00b::
~SC00c::
~SC00d::
~SC00e::
~SC00f::
~SC010::
~SC011::
~SC012::
~SC013::
~SC014::
~SC015::
~SC016::
~SC017::
~SC018::
~SC019::
~SC01a::
~SC01b::
~SC01c::
~SC01d::
~SC01e::
~SC01f::
~SC020::
~SC021::
~SC022::
~SC023::
~SC024::
~SC025::
~SC026::
~SC027::
~SC028::
~SC029::
~SC02a::
~SC02b::
~SC02c::
~SC02d::
~SC02e::
~SC02f::
~SC030::
~SC031::
~SC032::
~SC033::
~SC034::
~SC035::
~SC036::
~SC037::
~SC038::
~SC039::
~SC03a::
~SC03b::
~SC03c::
~SC03d::
~SC03e::
~SC03f::
~SC040::
~SC041::
~SC042::
~SC043::
~SC044::
~SC045::
~SC046::
~SC047::
~SC048::
~SC049::
~SC04a::
~SC04b::
~SC04c::
~SC04d::
~SC04e::
~SC04f::
~SC050::
~SC051::
~SC052::
~SC053::
~SC054::
~SC055::
~SC056::
~SC057::
~SC058::
~SC059::
~SC05a::
~SC05b::
~SC05c::
~SC05d::
~SC05e::
~SC05f::
~SC060::
~SC061::
~SC062::
~SC063::
~SC064::
~SC065::
~SC066::
~SC067::
~SC068::
~SC069::
~SC06a::
~SC06b::
~SC06c::
~SC06d::
~SC06e::
~SC06f::
~SC070::
~SC071::
~SC072::
~SC073::
~SC074::
~SC075::
~SC076::
~SC077::
~SC078::
~SC079::
~SC07a::
~SC07b::
~SC07c::
~SC07d::
~SC07e::
~SC07f::
~SC080::
~SC081::
~SC082::
~SC083::
~SC084::
~SC085::
~SC086::
~SC087::
~SC088::
~SC089::
~SC08a::
~SC08b::
~SC08c::
~SC08d::
~SC08e::
~SC08f::
~SC090::
~SC091::
~SC092::
~SC093::
~SC094::
~SC095::
~SC096::
~SC097::
~SC098::
~SC099::
~SC09a::
~SC09b::
~SC09c::
~SC09d::
~SC09e::
~SC09f::
~SC0a0::
~SC0a1::
~SC0a2::
~SC0a3::
~SC0a4::
~SC0a5::
~SC0a6::
~SC0a7::
~SC0a8::
~SC0a9::
~SC0aa::
~SC0ab::
~SC0ac::
~SC0ad::
~SC0ae::
~SC0af::
~SC0b0::
~SC0b1::
~SC0b2::
~SC0b3::
~SC0b4::
~SC0b5::
~SC0b6::
~SC0b7::
~SC0b8::
~SC0b9::
~SC0ba::
~SC0bb::
~SC0bc::
~SC0bd::
~SC0be::
~SC0bf::
~SC0c0::
~SC0c1::
~SC0c2::
~SC0c3::
~SC0c4::
~SC0c5::
~SC0c6::
~SC0c7::
~SC0c8::
~SC0c9::
~SC0ca::
~SC0cb::
~SC0cc::
~SC0cd::
~SC0ce::
~SC0cf::
~SC0d0::
~SC0d1::
~SC0d2::
~SC0d3::
~SC0d4::
~SC0d5::
~SC0d6::
~SC0d7::
~SC0d8::
~SC0d9::
~SC0da::
~SC0db::
~SC0dc::
~SC0dd::
~SC0de::
~SC0df::
~SC0e0::
~SC0e1::
~SC0e2::
~SC0e3::
~SC0e4::
~SC0e5::
~SC0e6::
~SC0e7::
~SC0e8::
~SC0e9::
~SC0ea::
~SC0eb::
~SC0ec::
~SC0ed::
~SC0ee::
~SC0ef::
~SC0f0::
~SC0f1::
~SC0f2::
~SC0f3::
~SC0f4::
~SC0f5::
~SC0f6::
~SC0f7::
~SC0f8::
~SC0f9::
~SC0fa::
~SC0fb::
~SC0fc::
~SC0fd::
~SC0fe::
~SC0ff::
  count++
return


The count variable keeps the count of all keys pressed. I hope you are not trying to make a key logger. Would give a bad name to ahk, and cause AV software to catch all compiled ahk scripts as trojans, after it gets popular.


Report this post
Top
 Profile  
Reply with quote  
PostPosted: March 22nd, 2005, 8:35 pm 
Offline

Joined: February 26th, 2005, 5:36 am
Posts: 21
NO, NO, NO - No keylogger, but the smiley is cause I wouldn't use this language at least. Would need it much smaller, self install all that jazz lol - I used to work in Casino industry so we faced all the dirty tricks.

I am doing something similar to what another user on here was looking to do for an online game which being able to duo box (read log to fire off spells etc when sent a message), however I am doing a totally different set of functionality (not as much log explicit).

However the point of me even writing this software and using AHK is two fold:
:arrow: its a free open source tool that if i design this right will do the job and is the right tool for that job. If I can accomplish the project with all aspects in mind, it will go to show the AHK can be used even in more products.
:arrow: I am a suffer of CTS, however love programming, playing my online games and other computer activities. However as we all know there is ALOT of keyboard and mouse activity in many games/software packages. Not only do I want my tool to be helpful - but I want it to SHOW the user just how much it is helping - thats the goal.

So - no keyboard logger and I guess then my theory was right - trap everything as it goes through - thanks for the code as it saves time for sure. Any thoughts on the mouse movement - buttons of course I can figure :)

Thanks again all!

V.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 22nd, 2005, 9:59 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
Here is a shorter script using Input. Modifier keys (Ctrl, Shift, Alt, Win, CapsLock…) are counted even if they are pressed alone. Special keys, like Pause, Esc and Mouse-clicks are also counted after the script is loaded. Win-= shows the actual count in a MsgBox, Win-0 resets the count to 0. Choose whatever keys are not used in your apllication.
Code:
Loop
{
Input Key, L1 V, {ScrollLock}{CapsLock}{NumLock}{TAB}{Esc}{BS}{Enter}{PrintScreen}{Pause}{LControl}{RControl}{LAlt}{RAlt}{LShift}{RShift}{LWin}{RWin}{F1}{F2}{F3}{F4}{F5}{F6}{F7}{F8}{F9}{F10}{F11}{F12}{Left}{Right}{Up}{Down}{Home}{End}{PgUp}{PgDn}{Del}{Ins}
cnt++
}

~*LButton::
~*RButton::
~*MButton::
   cnt++
return

#=::     ; display current key-press + mouse-click count
MsgBox %cnt%
return

#0::     ; restart counting
cnt =
return
All the {Key} names after the Input command should be in one very long line. The line breaks are introduced by your browser.


Report this post
Top
 Profile  
Reply with quote  
PostPosted: March 23rd, 2005, 1:46 am 
Offline

Joined: February 26th, 2005, 5:36 am
Posts: 21
Laszlo and all, thanks for the input. Your functions all worked great. In the end I realize that this must run in its own thread, seperate from my main program as it has its own gui as well.

My program's over a couple thousand lines already, and I have been breaking my files into logical 'classes' or groups if you will of subroutines. Using a unique nameing system based on the groups and subroutines to avoid variable problems and such.

However am I missing something, or is the only way I can really do this is to compile a seperate EXE that is the keystroke counter, and start it from my main program with a run command? Then do a interprocess communication? Is there anyway to start a AHK based code thread seperately?

Thanks again everyone!

V.


Report this post
Top
 Profile  
Reply with quote  
PostPosted: March 24th, 2005, 5:21 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
valenfor wrote:
is the only way I can really do this is to compile a seperate EXE that is the keystroke counter, and start it from my main program with a run command? Then do a interprocess communication? Is there anyway to start a AHK based code thread seperately?
Scripts are quasi-multi-threaded, so in most cases you can have them doing multiple things simultaneously. Have you tried combining the script above with your "main script"?


Report this post
Top
 Profile  
Reply with quote  
PostPosted: March 24th, 2005, 8:14 pm 
Offline

Joined: February 26th, 2005, 5:36 am
Posts: 21
I spent a few hours after getting that last bit of code and played with it and tried finding a way to implement it in my existing startup etc. I concidered timed start, hotkey start etc etc. But in the end this seemed a bit similar to me as another thread where everyone was discussing reading a log file that was consistently being written to. In the way that if you want them to startup and just run until stopped - I can't gosub it, i guess I could do a 1 timed startup with timer or such (but here I am actually back to thinking of solution lol - which is all I really need to do more of).

My Kudo's to you Chris, I programmed in alot of different languages and can't wait to browse your source one day when I am done with this project. I am writing a project to help script out some of the keystrokes from games that we play. Whats funny is of course we know alot of people make their own or hack their way - whats funnier is how time consuming it can be to create forms, data manage, etc to make things 'user friendly'. A project to do while awaiting CTS surgery and while out of employment.

This is my first project in AHK, and over about 2500 lines now and the other day I went through a bloat cut so I could get done the priorities. Trying to beat a surgery deadline. Maybe if this one works well enough I can create a new job of my own lol.

So after the long winded - the short is I found one quick way and didn't engineer farther. Still new to the language and learning what I can push and pull. The past few days has been fun with associate array data structures and manipulating them with INI's into forms etc. Fun fun.

Rajat - SmartGUI rocks too!

Thanks agian all!

V


Report this post
Top
 Profile  
Reply with quote  
 Post subject: high numbers
PostPosted: December 19th, 2008, 8:34 am 
Offline

Joined: June 18th, 2006, 8:47 am
Posts: 346
Location: Phoenix, AZ
I'm trying to finish a script that keeps track of how many keystrokes in the last 12 hours. One problem I have is holding control or other buttons causes the count to go really high.
I have some code here that avoids the high numbers, by checking for duplicates, but it fails to register separate control key presses. Not a big problem as very accurate statistics doesn't add much value.
The next problem for me to solve is keeping just the last 12 hours of counts.

Code:
SetTimer, s_UpdateCount, 15000

Loop
{
Input Key, L1 IV, {ScrollLock}{CapsLock}{NumLock}{TAB}{Esc}{BS}{Enter}{PrintScreen}{Pause}{LControl}{RControl}{LAlt}{RAlt}{LShift}{RShift}{LWin}{RWin}{F1}{F2}{F3}{F4}{F5}{F6}{F7}{F8}{F9}{F10}{F11}{F12}{Left}{Right}{Up}{Down}{Home}{End}{PgUp}{PgDn}{Del}{Ins}
if (ErrorLevel <> v_PriorKey)
  {
    cnt++
    v_PriorKey = %ErrorLevel%
  }
if (ErrorLevel = Max)
  {
    cnt++
    v_PriorKey = %ErrorLevel%
  }
}
return

~*LButton::
~*RButton::
~*MButton::
   cnt++
return

s_UpdateCount:
FileAppend, %cnt%`r`n, %A_ScriptDir%\Key.log
cnt =
return


Thanks Laszlo for the code!


Report this post
Top
 Profile  
Reply with quote  
 Post subject: sortof
PostPosted: December 19th, 2008, 10:43 am 
Offline

Joined: June 18th, 2006, 8:47 am
Posts: 346
Location: Phoenix, AZ
This is heading in the right direction. Still need to calculate the total, and create an ini instead of deleting a file. At home this will work perfectly, but at work I have multiple computers which complicates things.

Because I've been learning regex I think it is the solution to everything problem I see. Though it does work nicely here I think. But I wonder WWLD?

var1 = ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

Code:
FileDelete, %A_ScriptDir%\keycount.log
FileAppend, %var1%, %A_ScriptDir%\keycount.log


SetTimer, s_Reset, 900000 ; every fifteen minutes

Loop
{
Input Key, L1 V, {ScrollLock}{CapsLock}{NumLock}{TAB}{Esc}{BS}{Enter}{PrintScreen}{Pause}{LControl}{RControl}{LAlt}{RAlt}{LShift}{RShift}{LWin}{RWin}{F1}{F2}{F3}{F4}{F5}{F6}{F7}{F8}{F9}{F10}{F11}{F12}{Left}{Right}{Up}{Down}{Home}{End}{PgUp}{PgDn}{Del}{Ins}
if ErrorLevel contains EndKey
  {
if (ErrorLevel <> v_PriorEndKey)
      {
        v_Count++
      }
    v_PriorEndKey = %ErrorLevel%
  }
if ErrorLevel contains Max
  {
    v_Count++
  }
}
return

~*LButton::
~*RButton::
~*MButton::
   v_Count++
return

s_Reset:
FileRead, v_File, %A_ScriptDir%\keycount.log
v_Results := RegexReplace(v_File, "^.*?,", "")
FileDelete, %A_ScriptDir%\keycount.log
FileAppend, %v_Results%`,%v_Count%, %A_ScriptDir%\keycount.log
v_Count =
v_Results =
return


Report this post
Top
 Profile  
Reply with quote  
PostPosted: April 23rd, 2009, 9:24 pm 
Offline

Joined: July 31st, 2008, 1:19 am
Posts: 33
I'm not into logging things, but I'd like to log how much time a key was pressed during a period (say game time). I wanna log keys a,s,d,w by times pressed, so in the end I get how much time I was travelling into any direction in a FPS game. Here's my code so far:

Code:
; Overall time of moving into a certain direction
forward := 0
forwardleft := 0
forwardright := 0
back := 0
backleft := 0
backright := 0
right := 0
left := 0

; Is a key pressed?
forwardD := false
backD := false
leftD := false
rightD := false

   ~w::
      if (!forwardD) {
         forwardD := true
      } else {
         if (rightD) {
            Send {Up}{Shift Down}{Home}{Shift Up}forward-right
            forwardright += %A_TimeSincePriorHotkey%
         } else if (leftD) {
            Send {Up}{Shift Down}{Home}{Shift Up}forward-left
            forwardleft += %A_TimeSincePriorHotkey%
         } else {
            Send {Up}{Shift Down}{Home}{Shift Up}forward
            forward += %A_TimeSincePriorHotkey%
         }
      }
   return
   
   ~w Up::
      forwardD := false
   return
   
   ~s::
      if (!backD) {
         backD := true
      } else {
         if (rightD) {
            Send {Up}{Shift Down}{Home}{Shift Up}back-right
            backright += %A_TimeSincePriorHotkey%
         } else if (leftD) {
            Send {Up}{Shift Down}{Home}{Shift Up}back-left
            backleft += %A_TimeSincePriorHotkey%
         } else {
            Send {Up}{Shift Down}{Home}{Shift Up}back
            back += %A_TimeSincePriorHotkey%
         }
      }
   return
   
   ~s Up::
      backD := false
   return
   
   ~a::
      if (!leftD) {
         leftD := true
      } else {
         if (!forwardD && !backD) {
            Send {Up}{Shift Down}{Home}{Shift Up}left
            left += %A_TimeSincePriorHotkey%
         }
      }
   return
   
   ~a Up::
      leftD := false
   return
   
   ~d::
      if (!rightD) {
         rightD := true
      } else {
         if (!forwardD && !backD) {
            Send {Up}{Shift Down}{Home}{Shift Up}right
            right += %A_TimeSincePriorHotkey%
         }
      }
   return
   
   ~d Up::
      rightD := false
   return
   
   F2::
      Reload
   return
   
   F4::
      MsgBox, forward %forward%.`nback %back%.`nleft %left%.`nright %right%.`nforward-left %forwardleft%.`nforward-right %forwardright%.`nback-left %backleft%.`nback-right %backright%.`n
   return

This works, but not as I want it. The problem is in repetition of keys. Try this (say in Notepad) :
press and hold down key a then press and hold down s (still holding a) and then release s only (still holding down a). The problem is that a is not repeating anymore -> doesn't log time.
Any idea how to get around that?

Originally I wanted to log the time when a key was pressed and only act (add time) when the key was released. But for that I need time in milliseconds: I would use A_Now, but has precision only in seconds. Is it possible to use something similar?


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: chaosad, specter333, Yahoo [Bot] and 56 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group