topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Saturday December 7, 2024, 3:11 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Last post Author Topic: Key counting script  (Read 24758 times)

Robby250

  • Participant
  • Joined in 2011
  • *
  • default avatar
  • Posts: 18
    • View Profile
    • Donate to Member
Key counting script
« on: August 25, 2011, 02:07 PM »
Hi there,

I was led to this forum after searching on the internet for a key counting software, to be exact at skwire's Keycounter discussion page. There I reported a few issues with the software and he replied that those cannot be resolved due to the limitations of Autohotkey; then gave me a simple script for keycounting I could work on. Here's the script:

Are you familiar with AutoHotkey programming at all?  If so, here's a quick snippet I wrote that will do what you want for letters a-z and numbers 0-9.  Press F1 at anytime to see a simple message box showing your keystroke stats.  You could easily extend this to cover all keys, to save/load data, display data in a more elegant way, etc.

Now, I thought that it would be better if I took the script out of the quote:

Code: Autohotkey [Select]
  1. myKeys := "abcdefghijklmnopqrstuvwxyz1234567890"
  2.  
  3. ; Iterate through myKeys variable and create a hotkey for each letter and number.
  4. Loop, Parse, myKeys
  5. {
  6.     Hotkey, ~*%A_LoopField% up, CountKeys, On
  7. }
  8.  
  9. Return ; End of auto-execute section.
  10.  
  11.  
  12. CountKeys:
  13. {
  14.     ; Get the third character from the left of the hotkey name.
  15.     StringMid, myKey, A_ThisHotkey, 3, 1
  16.    
  17.     ; Increase character counter and total counter.
  18.     %myKey%_Count++
  19.     Total_Count++
  20. }
  21. Return
  22.  
  23. F1::
  24. {
  25.     ; Null out report variable.
  26.     myReport := ""
  27.    
  28.     ; Iterate over myKeys variable and build out report, key by key.
  29.     Loop, Parse, myKeys
  30.     {
  31.         myReport .= A_LoopField . ":`t" . %A_LoopField%_Count . "`n"
  32.     }
  33.    
  34.     ; Display report with total at the bottom.
  35.     MsgBox, % myReport . "`nTotal:`t" . Total_Count
  36. }
  37. Return

Unfortunately, I do not know any Autohotkey programming, and I basically want this to cover the whole keyboard, auto save the counter data and load it on script startup.

The reason of why I want this is because I am getting a new keyboard soon and I want to track each keypress individually and total, out of curiosity. If it matters (for which keys to add to the counter), I will be getting a Razer BlackWidow: http://tbreak.com/te...h/files/DSC00056.jpg

The initial issues I found with KeyCounter and I do not want to happen are: repeated keys (e.g. holding W for 5 seconds, it repeats the key many times) were being taken in consideration by the KeyCounter. I only want a single keystroke count; and keys combined with a modifier (e.g. alt+2; ctrl+shift+E, etc.), the modifier was being counted but the key(s) under the modifier were not. I wish they were.

skwire,
Thanks for this snippet, I replied at KeyCounter's discussion thread, but you probably did not see the post, were too busy, or whatever the reason is, it does not matter, but I think that you are reading the forums you are moderating :).

EDIT: Ah, I just saw the "Post New Requests Here" page, was I supposed to make the thread there? I am sorry.
« Last Edit: August 25, 2011, 02:24 PM by Robby250 »

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,287
    • View Profile
    • Donate to Member
Re: Key counting script
« Reply #1 on: August 25, 2011, 02:36 PM »
@Robby250: I went ahead and moved your post so no worries.  Apologies for the lack of reply on the KeyCounter thread.  I've been crazy busy with work the past couple of weeks so I haven't had much time to reply.  I can probably find time next week to flesh out that snippet I gave you.  If you don't mind, and to save me time, I'd like to just write it without a GUI.  In other words, you would simply view the data in any text editor.  It will be saved/loaded across sessions, though.  Would that be okay?

Robby250

  • Participant
  • Joined in 2011
  • *
  • default avatar
  • Posts: 18
    • View Profile
    • Donate to Member
Re: Key counting script
« Reply #2 on: August 25, 2011, 02:40 PM »
Yeah, that is fine, but can it auto save when the script is shutting down (computer shutdown), or can it only save ocasionally, and the data in between saves is lost? I would like it to be as accurate as possible. :p

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,287
    • View Profile
    • Donate to Member
Re: Key counting script
« Reply #3 on: August 25, 2011, 03:18 PM »
Yeah, that is fine, but can it auto save when the script is shutting down (computer shutdown), or can it only save ocasionally, and the data in between saves is lost? I would like it to be as accurate as possible. :p

Auto-saving on computer shutdown can be hit-or-miss.  So, sure, I can make it auto-save every X number of seconds.  What are you comfortable with?  Ten seconds?  Thirty?

Robby250

  • Participant
  • Joined in 2011
  • *
  • default avatar
  • Posts: 18
    • View Profile
    • Donate to Member
Re: Key counting script
« Reply #4 on: August 25, 2011, 03:23 PM »
If it doesn't produce any performance issues I'm good with even less than 10 seconds. Also, by auto-saving I meant that the script detects when it is being turned off and saves... or something like that ¯\(°_o)/¯.
« Last Edit: August 25, 2011, 03:30 PM by Robby250 »

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,287
    • View Profile
    • Donate to Member
Re: Key counting script
« Reply #5 on: August 25, 2011, 04:23 PM »
Yes, I can easily make it save when YOU initiate closing the script.  Choosing Exit from its own tray menu or some such.  What I meant was that catching the system-wide shutdown message Windows sends when shutting down is hit-or-miss.  As for performance issues, that will be up to you; it should be negligible.

Robby250

  • Participant
  • Joined in 2011
  • *
  • default avatar
  • Posts: 18
    • View Profile
    • Donate to Member
Re: Key counting script
« Reply #6 on: August 25, 2011, 04:31 PM »
Just select a rate that you consider safe enough and not make it an overkill. If there is a problem with it I will probably be able to edit the saving rate anyway, because I think there are obvious signs such as Savefile bla bla *file name* around there along with a number it is pretty noticeable that that is the saving rate, is it not?
That is, considering you are making it an .ahk script and not .exe.

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,287
    • View Profile
    • Donate to Member
Re: Key counting script
« Reply #7 on: August 29, 2011, 05:33 PM »
@Robby250: I started work on this but there is one caveat.  Let me try to explain.  The original app, KeyCounter, should technically be called CharacterCounter since that's actually what it's doing.  Counting characters...not keystrokes.  So, this version I'm making for you is an up-event keystroke counter.  This brings us to the caveat.  Since it's a keystroke counter, it doesn't know about something like, for instance, the exclamation point.  The exclamation point is a character, not a key.  So, for an exclamation point, this new app will register two keystroke up-events: "Right Shift" and the "1" key.  Does that make sense?  Is this going to be an issue?

Robby250

  • Participant
  • Joined in 2011
  • *
  • default avatar
  • Posts: 18
    • View Profile
    • Donate to Member
Re: Key counting script
« Reply #8 on: August 30, 2011, 02:55 AM »
@Robby250: I started work on this but there is one caveat.  Let me try to explain.  The original app, KeyCounter, should technically be called CharacterCounter since that's actually what it's doing.  Counting characters...not keystrokes.  So, this version I'm making for you is an up-event keystroke counter.  This brings us to the caveat.  Since it's a keystroke counter, it doesn't know about something like, for instance, the exclamation point.  The exclamation point is a character, not a key.  So, for an exclamation point, this new app will register two keystroke up-events: "Right Shift" and the "1" key.  Does that make sense?  Is this going to be an issue?
No, actually that's exactly what I want, I even mentioned in the other thread that I want for example ' and " to count as the same key, which is another difference to the KeyCounter.
Also, I'm wondering. Can it notice the difference between the right shift and left shift; right ctrl and left? Or do some of them identify as exactly the same? And recently I've noticed that my right Alt produces both Alt and Ctrl... Would that count as 2 keystrokes?

And by the way, you don't need such an extended explanation, I can understand :P.

Something cool I thought of but would take too much time and effort to make, is an interface with a keyboard layout like this one: http://patorjk.com/typing-speed-test/
After you're done with the test, it colors the keys by response time (I was thinking of counting by amount of presses) and on mouseover shows counts of the keys... But as I said, isn't something for such a simple script like this.

Another thing I want to know with Autohotkey, and you seem like someone who knows about it, is if you can bind several keys to a single key. Not only to send them on a press, but the selected keys to be pressed when I press the key they're bound to, and release when I release it. Do you know if that's possible? I haven't found anything like this anywhere. Not related to this script though.
« Last Edit: August 30, 2011, 05:23 AM by Robby250 »

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,287
    • View Profile
    • Donate to Member
Re: Key counting script
« Reply #9 on: August 30, 2011, 07:58 AM »
No, actually that's exactly what I want, I even mentioned in the other thread that I want for example ' and " to count as the same key, which is another difference to the KeyCounter.

Great.

Also, I'm wondering. Can it notice the difference between the right shift and left shift; right ctrl and left? Or do some of them identify as exactly the same? And recently I've noticed that my right Alt produces both Alt and Ctrl... Would that count as 2 keystrokes?

I have it written so that it does separate left/right Control, Alt, Shift and Win keys.  That being said, not all keyboards are the same so your results may vary.  It works here on my Microsoft Natural Keyboard Pro.

Another thing I want to know with Autohotkey, and you seem like someone who knows about it, is if you can bind several keys to a single key. Not only to send them on a press, but the selected keys to be pressed when I press the key they're bound to, and release when I release it. Do you know if that's possible? I haven't found anything like this anywhere. Not related to this script though.

Sure, that's possible.  I assume you mean this for gaming purposes.  If so, check out the AutoHotkey forum.  It's probably full of scripts like this.

Robby250

  • Participant
  • Joined in 2011
  • *
  • default avatar
  • Posts: 18
    • View Profile
    • Donate to Member
Re: Key counting script
« Reply #10 on: August 30, 2011, 08:50 AM »
Sure, that's possible.  I assume you mean this for gaming purposes.  If so, check out the AutoHotkey forum.  It's probably full of scripts like this.
You mean the AutoHotkey board on Donationcoder or the AutoHotkey forums made by them? I've searched a lot using google anyway, and all I have found is something like this:
If I want left alt to press alt, ctrl and shift it should be like this: Lalt::alt & ctrl & shift, or I've even tried Lalt::!^Shift.

Problem is, it isn't working.
I've read the tutorial (I admit that pretty summarily) and couldn't find anything helpful. I've also looked on the Autohotkey forum and a few promising looking threads disappointed me. I thought that bringing the question here would shorten all the hassle.

I have it written so that it does separate left/right Control, Alt, Shift and Win keys.  That being said, not all keyboards are the same so your results may vary.  It works here on my Microsoft Natural Keyboard Pro.

It seems that the Razer BlackWidow doesn't have a right windows key, but it has a menu key and a function key instead. Could you include those too please?

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,287
    • View Profile
    • Donate to Member
Re: Key counting script
« Reply #11 on: August 30, 2011, 08:53 AM »
It seems that the Razer BlackWidow doesn't have a right windows key, but it has a menu key and a function key instead. Could you include those too please?

If, by the menu key, you mean the context menu key (commonly called the Apps key), yes, that's included.  Your function key (and those custom ones along your keyboard's left side), probably not.

Robby250

  • Participant
  • Joined in 2011
  • *
  • default avatar
  • Posts: 18
    • View Profile
    • Donate to Member
Re: Key counting script
« Reply #12 on: August 30, 2011, 08:56 AM »
If, by the menu key, you mean the context menu key (commonly called the Apps key)
Yes, I've included a photo of the keyboard in the original post in case you missed it.

Never mind my previous question with the modifiers, I found that out, and now a mouse button acts as Ctrl+shift, another as alt+shift, and the left Windows key as ctrl+alt+shift. I'm wondering if they count when I'm pressing them, because I wouldn't want them to count as modifiers, but I can deal with it; the actual binds I've done are:
Code: Autohotkey [Select]
  1. LWin::
  2. Send {Alt down}
  3. Send {Ctrl down}
  4. Send {Shift down}
  5. KeyWait LWin
  6. Send {Alt up}
  7. Send {Ctrl up}
  8. Send {Shift up}
  9. return
  10.  
  11. Xbutton2::
  12. Send {Alt down}
  13. Send {Shift down}
  14. Keywait Xbutton2
  15. Send {Alt up}
  16. Send {Shift up}
  17. return
  18.  
  19. Xbutton1::
  20. Send {Ctrl down}
  21. Send {Shift down}
  22. Keywait Xbutton1
  23. Send {Ctrl up}
  24. Send {Shift up}
  25. return


Also, I'm using a colemak keyboard layout, which has been installed through the "Keyboards and Languages" menu. Some games seem to indentify it as qwerty, and others indentify it correctly. Would this be a problem for which key is counted in the program?
« Last Edit: August 30, 2011, 11:29 AM by Robby250 »

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,287
    • View Profile
    • Donate to Member
Re: Key counting script
« Reply #13 on: September 01, 2011, 12:11 AM »
Give this a try:  http://skwire.dcmemb.../snacks/KeyCount.zip

Regarding the colemak layout, I don't know for sure but I doubt the key counts are going to correspond to the right keys.
« Last Edit: September 01, 2011, 07:21 AM by skwire »

Robby250

  • Participant
  • Joined in 2011
  • *
  • default avatar
  • Posts: 18
    • View Profile
    • Donate to Member
Re: Key counting script
« Reply #14 on: September 01, 2011, 05:17 AM »
It says "404 Not Found" on anything below and including /snacks/.

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,287
    • View Profile
    • Donate to Member
Re: Key counting script
« Reply #15 on: September 01, 2011, 07:22 AM »
Sorry about that.  I've fixed it.

Robby250

  • Participant
  • Joined in 2011
  • *
  • default avatar
  • Posts: 18
    • View Profile
    • Donate to Member
Re: Key counting script
« Reply #16 on: September 01, 2011, 09:05 AM »
Oh my god. That is perfect. It counts the key layout correctly, while not counting the Autohotkey modifier changes I've made.

Should I edit this post if I find any problems with the app, or make a new post to bump the thread? Thanks a lot! I appreciate it.
« Last Edit: September 01, 2011, 09:08 AM by Robby250 »

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,287
    • View Profile
    • Donate to Member
Re: Key counting script
« Reply #17 on: September 01, 2011, 09:12 AM »
You're welcome.  I'm glad to hear it works with your keyboard layout.  You can just post here if you have any issues; I'll get notified.  If, for some reason, I don't reply, pick something from this page:  http://skwire.dcmemb...wb/pages/contact.php

Robby250

  • Participant
  • Joined in 2011
  • *
  • default avatar
  • Posts: 18
    • View Profile
    • Donate to Member
Re: Key counting script
« Reply #18 on: September 01, 2011, 09:26 AM »
Ah. I remembered to try out if the right alt counts as 2 keystrokes. And indeed it counts as one to right alt and one to left ctrl. Is this fixable? I can live with it though, Since I never normally use AltGr as it's called.

Also, my mouse has a thumb scroll that I can bind on whatever keystroke I want. So I binded it with Left and Right from the keyboard, and this seems to count too. I need to bind it something so that I can use it in games, and I've chosen left and right to be able to use horizontal scrolling as well. Maybe you know some mouse keys or virtual buttons or anything that I can bind in those places, to make it usable but also not be counted? A software to simulate those to input them into the mouse's software would also help. Thanks.
« Last Edit: September 01, 2011, 09:37 AM by Robby250 »

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,287
    • View Profile
    • Donate to Member
Re: Key counting script
« Reply #19 on: September 01, 2011, 09:51 AM »
Ah. I remembered to try out if the right alt counts as 2 keystrokes. And indeed it counts as one to right alt and one to left ctrl. Is this fixable? I can live with it though, Since I never normally use AltGr as it's called.

I can add in the non-specific Control/Alt/Shift modifiers and see if that makes a difference.

Also, my mouse has a thumb scroll that I can bind on whatever keystroke I want. So I binded it with Left and Right from the keyboard, and this seems to count too.

The only thing I can suggest is to use something less common like F11 & F12 or something.

Robby250

  • Participant
  • Joined in 2011
  • *
  • default avatar
  • Posts: 18
    • View Profile
    • Donate to Member
Re: Key counting script
« Reply #20 on: September 01, 2011, 09:53 AM »
The only thing I can suggest is to use something less common like F11 & F12 or something.
It's not that it adds to the specific key what bothers me, but that it adds to the total.

I'm thinking... there's Mouse button 1, left click, 2, right click, 3, middle scroll click, then 4 and 5 the side buttons this mouse has. Maybe there are Mouse buttons 6 and 7 too or something similar?

Edit1:I just remembered, since I'm using modifiers on the mouse buttons 4 and 5 now these are unused, so I can just put these on the thumb scroll. Silly me.
Any news of the AltGr fix though?
Edit2: Oh man... that actually didn't work... since as long as I have Xbutton1::ctrl for example, and the thumb scroll indentifies itself as exactly that, it now acts as a ctrl...

Edit3:The only thing I could think of, is for you to disable on the counter 2 buttons such as browser forward and backward, I bind them to the mouse button 4 and 5 using the mouse's software, then, using autohotkey, I make something like Browser_back::ctrl, and for the other alt, then mouse button 4 and 5 are free to use for the thumb scroll.

Edit4:I binded those like I said, now all I need is a version of the app without the browser forward and back. Could you make one for me please?
« Last Edit: September 01, 2011, 02:57 PM by Robby250 »

Robby250

  • Participant
  • Joined in 2011
  • *
  • default avatar
  • Posts: 18
    • View Profile
    • Donate to Member
Re: Key counting script
« Reply #21 on: September 01, 2011, 03:50 PM »
Double post as a notification perhaps?

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,287
    • View Profile
    • Donate to Member
Re: Key counting script
« Reply #22 on: September 01, 2011, 05:11 PM »
Double post as a notification perhaps?

Please understand that I am employed full-time and that I do these Coding Snacks when I can get to them in my spare time.

Any news of the AltGr fix though?

If I'm understanding your issue, I don't think this is something I can fix.

Edit4:I binded those like I said, now all I need is a version of the app without the browser forward and back. Could you make one for me please?

Grab the latest build from the same URL as above.  In this build you will find two additional files: Keys.txt & KeyExclusions.txt.  Keys.txt contains a complete list of countable key names.  If you want keys excluded, add the respective names, one per line, to the KeyExclusions.txt file and restart KeyCount.
« Last Edit: September 01, 2011, 05:24 PM by skwire, Reason: Grammatical error. »

Robby250

  • Participant
  • Joined in 2011
  • *
  • default avatar
  • Posts: 18
    • View Profile
    • Donate to Member
Re: Key counting script
« Reply #23 on: September 01, 2011, 05:33 PM »
Please understand that I am employed full-time and that I do these Coding Snacks when I can get to them in my spare time.
Don't get me wrong, I'm not trying to call you faster, but I wrote that just in case you wouldn't check this thread because there aren't any new posts.

Also, that works just fine, I don't think that I'll need any other updates, I appreciate your work. Thank you very much.

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,287
    • View Profile
    • Donate to Member
Re: Key counting script
« Reply #24 on: September 01, 2011, 05:36 PM »
Also, that works just fine, I don't think that I'll need any other updates, I appreciate your work. Thank you very much.

You're welcome.  I'm glad I was able to help.   :)