Welcome Guest.   Make a donation to an author on the site November 23, 2014, 07:24:16 AM  *

Please login or register.
Or did you miss your validation email?


Login with username and password (forgot your password?)
Why not become a lifetime supporting member of the site with a one-time donation of any amount? Your donation entitles you to a ton of additional benefits, including access to exclusive discounts and downloads, the ability to enter monthly free software drawings, and a single non-expiring license key for all of our programs.


You must sign up here before you can post and access some areas of the site. Registration is totally free and confidential.
 
Free DonationCoder.com Member Kit: Submit Request.
   
   Forum Home   Thread Marks Chat! Downloads Search Login Register  
Pages: [1] 2 Next   Go Down
  Reply  |  New Topic  |  Print  
Author Topic: Key counting script  (Read 8581 times)
Robby250
Participant
*
Posts: 18

View Profile Give some DonationCredits to this forum member
« on: August 25, 2011, 02:07:11 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:

Formatted for Autohotkey with the GeSHI Syntax Highlighter [copy or print]
  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.  
  22. F1::
  23. {
  24.    ; Null out report variable.
  25.    myReport := ""
  26.  
  27.    ; Iterate over myKeys variable and build out report, key by key.
  28.    Loop, Parse, myKeys
  29.    {
  30.        myReport .= A_LoopField . ":`t" . %A_LoopField%_Count . "`n"
  31.    }
  32.  
  33.    ; Display report with total at the bottom.
  34.    MsgBox, % myReport . "`nTotal:`t" . Total_Count
  35. }

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/tech/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 smiley.

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:23 PM by Robby250 » Logged
skwire
Global Moderator
*****
Posts: 4,158



Another Coding Snack request? Om nom nom...

see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #1 on: August 25, 2011, 02:36:09 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?
Logged

Robby250
Participant
*
Posts: 18

View Profile Give some DonationCredits to this forum member
« Reply #2 on: August 25, 2011, 02:40:21 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
Logged
skwire
Global Moderator
*****
Posts: 4,158



Another Coding Snack request? Om nom nom...

see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #3 on: August 25, 2011, 03:18:43 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?
Logged

Robby250
Participant
*
Posts: 18

View Profile Give some DonationCredits to this forum member
« Reply #4 on: August 25, 2011, 03:23:40 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:36 PM by Robby250 » Logged
skwire
Global Moderator
*****
Posts: 4,158



Another Coding Snack request? Om nom nom...

see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #5 on: August 25, 2011, 04:23:49 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.
Logged

Robby250
Participant
*
Posts: 18

View Profile Give some DonationCredits to this forum member
« Reply #6 on: August 25, 2011, 04:31:23 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.
Logged
skwire
Global Moderator
*****
Posts: 4,158



Another Coding Snack request? Om nom nom...

see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #7 on: August 29, 2011, 05:33:01 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?
Logged

Robby250
Participant
*
Posts: 18

View Profile Give some DonationCredits to this forum member
« Reply #8 on: August 30, 2011, 02:55:35 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:59 AM by Robby250 » Logged
skwire
Global Moderator
*****
Posts: 4,158



Another Coding Snack request? Om nom nom...

see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #9 on: August 30, 2011, 07:58:03 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.
Logged

Robby250
Participant
*
Posts: 18

View Profile Give some DonationCredits to this forum member
« Reply #10 on: August 30, 2011, 08:50:39 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?
Logged
skwire
Global Moderator
*****
Posts: 4,158



Another Coding Snack request? Om nom nom...

see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #11 on: August 30, 2011, 08:53:51 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.
Logged

Robby250
Participant
*
Posts: 18

View Profile Give some DonationCredits to this forum member
« Reply #12 on: August 30, 2011, 08:56:22 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:
Formatted for Autohotkey with the GeSHI Syntax Highlighter [copy or print]
  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.  
  10. Xbutton2::
  11. Send {Alt down}
  12. Send {Shift down}
  13. Keywait Xbutton2
  14. Send {Alt up}
  15. Send {Shift up}
  16.  
  17. Xbutton1::
  18. Send {Ctrl down}
  19. Send {Shift down}
  20. Keywait Xbutton1
  21. Send {Ctrl up}
  22. Send {Shift up}


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:40 AM by Robby250 » Logged
skwire
Global Moderator
*****
Posts: 4,158



Another Coding Snack request? Om nom nom...

see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #13 on: September 01, 2011, 12:11:18 AM »

Give this a try:  http://skwire.dcmembers.com/apps/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:51 AM by skwire » Logged

Robby250
Participant
*
Posts: 18

View Profile Give some DonationCredits to this forum member
« Reply #14 on: September 01, 2011, 05:17:28 AM »

It says "404 Not Found" on anything below and including /snacks/.
Logged
skwire
Global Moderator
*****
Posts: 4,158



Another Coding Snack request? Om nom nom...

see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #15 on: September 01, 2011, 07:22:27 AM »

Sorry about that.  I've fixed it.
Logged

Robby250
Participant
*
Posts: 18

View Profile Give some DonationCredits to this forum member
« Reply #16 on: September 01, 2011, 09:05:25 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:45 AM by Robby250 » Logged
skwire
Global Moderator
*****
Posts: 4,158



Another Coding Snack request? Om nom nom...

see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #17 on: September 01, 2011, 09:12:03 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.dcmembers.com/wb/pages/contact.php
Logged

Robby250
Participant
*
Posts: 18

View Profile Give some DonationCredits to this forum member
« Reply #18 on: September 01, 2011, 09:26:24 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:11 AM by Robby250 » Logged
skwire
Global Moderator
*****
Posts: 4,158



Another Coding Snack request? Om nom nom...

see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #19 on: September 01, 2011, 09:51:53 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.
Logged

Robby250
Participant
*
Posts: 18

View Profile Give some DonationCredits to this forum member
« Reply #20 on: September 01, 2011, 09:53:47 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:36 PM by Robby250 » Logged
Robby250
Participant
*
Posts: 18

View Profile Give some DonationCredits to this forum member
« Reply #21 on: September 01, 2011, 03:50:04 PM »

Double post as a notification perhaps?
Logged
skwire
Global Moderator
*****
Posts: 4,158



Another Coding Snack request? Om nom nom...

see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #22 on: September 01, 2011, 05:11:29 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:32 PM by skwire; Reason: Grammatical error. » Logged

Robby250
Participant
*
Posts: 18

View Profile Give some DonationCredits to this forum member
« Reply #23 on: September 01, 2011, 05:33:27 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.
Logged
skwire
Global Moderator
*****
Posts: 4,158



Another Coding Snack request? Om nom nom...

see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #24 on: September 01, 2011, 05:36:06 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.   smiley
Logged

Pages: [1] 2 Next   Go Up
  Reply  |  New Topic  |  Print  
 
Jump to:  
   Forum Home   Thread Marks Chat! Downloads Search Login Register  

DonationCoder.com | About Us
DonationCoder.com Forum | Powered by SMF
[ Page time: 0.085s | Server load: 0.47 ]