Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Detection of multiple and long key presses


  • Please log in to reply
4 replies to this topic
halweg
  • Members
  • 127 posts
  • Last active: Jul 06 2015 06:54 AM
  • Joined: 27 Jan 2005
Back to the roots:
The most important thing in AHK is the pressing of hotkeys.
Why not have a build-in-detection of multiple or long key presses. Something like
F1:: Gosub open_help
F1x2:: Gosub open_knowledge_base
F1x3:: Gosub call_microsoft_hotline
F1long:: Gosub search_hotkey_forum
Using that feature in the current AHKs scripting is a little bit boring an costs a lot of script lines.
:cry:

jonny
  • Members
  • 2951 posts
  • Last active: Feb 24 2008 04:22 AM
  • Joined: 13 Nov 2004
It's really not that hard, as it is. Making it a built-in feature like that would take away from the fine-tuned control you can have over existing methods of doing this. For instance, here's code to detect a double-press of a button, using CapsLock as an example:

capslock::
keywait,capslock
keywait,capslock,d t0.5 ; Increase the "t" value for a longer timeout.
if errorlevel
return
msgbox,You double-pressed %a_thishotkey%.
return

And, to differentiate between long and short:

capslock::
KeyWait,capslock
if A_TimeSinceThisHotkey >= 850 ; in milliseconds.
MsgBox,Long Keypress.
else
MsgBox,Short Keypress.
return

These snippets are very simple, and (to me) easier to understand. Every step is fully configurable. Scripting, even AHK scripting, is not meant to be ridiculously easy to code, it's meant to give you control while being simpler than your average language. With that said, I think that this new feature idea is good, but simple enough to do with the existing functions and thus should not add more bloat to AHK for the sake of a few lines.

halweg
  • Members
  • 127 posts
  • Last active: Jul 06 2015 06:54 AM
  • Joined: 27 Jan 2005
It seems to be a philosophical difference between programmers by the one side and "end-users" that will simply reassign buttons by the other side. (Hope my English is understandable). :wink:
When I look at my script (I've a keyboard with some 20 extra application keys with multiple press detection) I see a lot of KEYWAITs, SETTIMERs, GOSUBs and IFs rather than RUNs and ::S :shock:
That fine tuning you mean may be Chris' task or whoever is developing AHK. Concerning the bloating to AHK it's difficult to me to understand why I can catch the pressing of three simultaneously pressed buttons while a simple double click isn't recognizable without special scripts and time handling.
Now I begin write some subroutines and libraries that help me keep my scripts free from multiple key press handling.
I know, the programmers are that people that helped me getting a very good keyboard handling. But the question is: What is the target user of AHK? And, of course: How much efforts cost some extra key recognition commands.
BTW: thanks for the new examples in detecting multiple and long key presses :D . Can you combine them :?:

jonny
  • Members
  • 2951 posts
  • Last active: Feb 24 2008 04:22 AM
  • Joined: 13 Nov 2004

That fine tuning you mean may be Chris' task or whoever is developing AHK.


Chris "fine tunes" AHK on a daily basis; it's called debugging. :D

What I actually meant was that not all things can be done with just one short line, and in some cases it's undesirable to have it that way. In this case, I think the current way to do it is just as good as any way that Chris would implement. There's too many variables to make it any more understandable anyway; imagine that you wanted one to activate upon a half-second press, and the other to activate on a full-second press. So Chris implements a function to set the default time-out for long hotkeys. But then you want this functionality in the double-presses too (combined, like you asked for above). So he adds another parameter to that function. Then suddenly you want more control over the speed of the double-presses, double-pressing modifiers, etc., etc. It may sound ridiculous, but take a closer look at the things I've mentioned above and you'll see they are logical to have with an implementation of this new feature. Before you know it, a custom double-press and long-press script will be almost as bloated as before, and just as hard, if not harder, to comprehend.

Aside from that, though, some of us like the hackier side of scripting (some think of this as the "dark side" :D ). Sometimes I like to see exactly what my script is doing and know how to tweak it however I like. In fact, I'm unsatisfied with some of the current AHK functions for this very reason. At the same time, though, I realize that some people don't care about the scripting and just want their job done. I think AHK currently does a great job of compromising between the two.

I hope I've explained my opinion clearly enough. However, if the majority thinks this new function would be a good idea, then I'm not one to try and stop it.

Concerning the bloating to AHK it's difficult to me to understand why I can catch the pressing of three simultaneously pressed buttons while a simple double click isn't recognizable without special scripts and time handling.


This is more difficult to answer, but the simplest way to say it is that hotkeys are already built into the OS. Double-pressing hotkeys are quite different, and Chris would have to use a different method to detect them. Thus, it's hard to compare them.

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
I think the idea of built-in multi-press hotkeys is a good one. I'm not saying it will be done any time soon, or that ultimately it will even be feasible (cost vs. benefit). I'm just saying the concept has appeal.

So thanks for discussing some of the pros and cons. These posts will serve as a valuable reference when the time comes to seriously consider such a feature.