Jump to content

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

Entering commands using double-tapped Shift


  • Please log in to reply
12 replies to this topic
RatThing
  • Members
  • 3 posts
  • Last active: Aug 08 2005 11:28 AM
  • Joined: 05 Aug 2005
(Sorry, apparently I wasn’t logged in when I posted my message.)

Please let me know if this is possible to do (and, if so, how to do it):

I’d like to be able to “double–tap” the left Shift key to bring up an input window, enter a command into that window, then press Shift again to execute the command. The idea is to be able to enter commands entirely with the left Shift key and the keys on the left side of a split keyboard.

Much obliged,

— Rat

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
What command do you want to execute? For the case when it is the name of a Windows executable, the following scripts works. If it is a special command for a game, you have to replace "run" with "Send", or similar.

There are a few tricks:
- You can define LShift as a hotkey. It has to check if it was activated within 300 ms again, as a possible indication of a double tap.
- If you want to catch further LShifts (for sending commands), you have to exit the hotkey routine, but still do some work. It is done by starting a timer, which calls the Inp function every 10 ms. Inp stops this timer immediately after activation, so it is executed only once, but not within the LShift hotkey routine.
- If LShift was pressed and the active window is the InputBox, which has been started in the Inp routine, we can Send {Enter}, so LShift activates the command. Esc will close it, as mouse clicks.
~Lshift::
   If (A_ThisHotkey = A_PriorHotkey and A_TimeSincePriorHotkey < 300)
      SetTimer Inp, 10
   Else IfWinActive ahk_class #32770
      Send {Enter}
Return

Inp:
   SetTimer Inp, Off
   InputBox cmd, Cmd Input, Type your command,, 200, 140
   Run %cmd%
Return


toralf
  • Moderators
  • 4035 posts
  • Last active: Aug 20 2014 04:23 PM
  • Joined: 31 Jan 2005
Hi rat,
Please search the forum. There was a topic by ezuk with the same request to execute commands only with rapid CTRL key presses.


PS: I'll remove your duplicate post.
Ciao
toralf
 
I use the latest AHK version (1.1.15+)
Please ask questions in forum on ahkscript.org. Why?
For online reference please use these Docs.

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
But here we had the extra challenge that inside a hotkey routine the same hotkey has to be triggered again. This timer trick is not easy to figure out or find in the help (I have seen it, but forgot where).

Litmus Red
  • Members
  • 139 posts
  • Last active: Nov 03 2005 05:01 PM
  • Joined: 25 Jul 2005
I really like your script, Lazlo.

I noticed the Start>Run window and Internet Explorer's Open window are also ahk_class #32770. Here's a modification of your script.

~Lshift::
If (A_ThisHotkey = A_PriorHotkey and A_TimeSincePriorHotkey < 300)
SetTimer Inp, 10
Else If (WinActive("ahk_class #32770") and WinActive("Cmd Input"))
Send {Enter}
Return

Inp:
SetTimer Inp, Off
InputBox cmd, Cmd Input, Type your command,, 200, 140
Run %cmd%
Return


toralf
  • Moderators
  • 4035 posts
  • Last active: Aug 20 2014 04:23 PM
  • Joined: 31 Jan 2005

But here we had the extra challenge that inside a hotkey routine the same hotkey has to be triggered again. This timer trick is not easy to figure out or find in the help (I have seen it, but forgot where).

Yes, I agree it is an extra challenge. But I'm sure your script at
http://www.autohotke...opic.php?t=4640
would have been a good starting point as well, since it is easy to extend. :) That's why I mentioned it.

As for the manual, under Threads it says:

Related to the above: A single script can have multiple simultaneous MsgBox, InputBox, FileSelectFile, and FileSelectFolder dialogs. This is achieved by launching a new thread (via hotkey, timed subroutine, or custom menu item) while a prior thread already has a dialog displayed.

By default, a given hotkey or hotstring subroutine cannot be run a second time if it is already running. Use #MaxThreadsPerHotkey to change this behavior.


Ciao
toralf
 
I use the latest AHK version (1.1.15+)
Please ask questions in forum on ahkscript.org. Why?
For online reference please use these Docs.

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
Thanks, toralf! I tried changing #MaxThreadsPerHotkey, as you suggest. It does allow simplifying the script (with the addition of Litmus Red):
#MaxThreadsPerHotkey 2

~Lshift::

   If (A_ThisHotkey = A_PriorHotkey and A_TimeSincePriorHotkey < 300)

   {

      InputBox cmd, Cmd Input, Type your command,, 200, 140

      Run %cmd%

   }

   Else If (WinActive("ahk_class #32770") and WinActive("Cmd Input"))

      Send {Enter}

Return
This version is a bit sensitive, though, as the auto-repeat function of the keyboard fires the hotkey twice, if you keep the Shift key pressed down long enough. If you have 2 InputBox-es open, the Shift key does not close any of them, as no more threads can be started. With more threads per hotkey, you could easily end up with several InputBox-es open. The original version does not open more than one InputBox at a time, so it looks more robust.

RatThing
  • Members
  • 3 posts
  • Last active: Aug 08 2005 11:28 AM
  • Joined: 05 Aug 2005
Wow, that’s amazing — I thought for sure it would be much more complicated than that. This AutoHotkey thing is awesome, as are you guys!

Since that worked out so well I wonder if you could tell me whether it’s possible to have a command enter as soon as I enter two keys. As an example, here’s what I’m doing currently (based on the script Laszlo provided):

#MaxThreadsPerHotkey 2 
~LCtrl:: 
   If (A_ThisHotkey = A_PriorHotkey and A_TimeSincePriorHotkey < 300) 
   {
      InputBox, strUserInput, Command, Please enter a command.
      IfEqual, strUserInput, ds, Run, https://signin.dell.com/premier/portal/login.aspx
      IfEqual, strUserInput, qq, Run, http://www.mapquest.com/
      IfEqual, strUserInput, ex, Run, C:\Program Files\Outlook Express\msimn.exe
   }
   Else If (WinActive("ahk_class #32770") and WinActive("Command")) 
      Send {Enter} 
Return
There are a number of other two–letter commands — this just lists a few examples. What I’d like to happen is to have the code execute as soon as I type, say, “ds” or “qq” without hitting Left Control again. So it’d go from Ctrl, Ctrl, d,s, Ctrl {execute} to Ctrl, Ctrl, d, s {execute}

Is that doable or is it getting too complicated?

Ultimately I’d like to get this to work without using an input box at all but that isn’t hugely important.

Thanks for your help!

— Rat

toralf
  • Moderators
  • 4035 posts
  • Last active: Aug 20 2014 04:23 PM
  • Joined: 31 Jan 2005
Please read the manual.

You are looking for hotstrings in the above case.

Regarding the last wish: Why do you ask us to help you to do this, when you want to do another thing? You can just use hotkeys to run things. You do not have to use the input box, just the command "run" that is started called by a hotkey.

I highly recommend you to read the manual.
Ciao
toralf
 
I use the latest AHK version (1.1.15+)
Please ask questions in forum on ahkscript.org. Why?
For online reference please use these Docs.

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
Now the task is: double tapping on the left Control key activates a hotstring-like functionality, but without the foreground application receiving the keystrokes. AHK does not directly provides this, we have to program it with catching keys as they are pressed, echo them in a separate window (like TrayTip) and act upon a match. Here is a quickie with the basic idea. It is not as tricky as reactivating hotkeys. There are also many alternatives, like ToolTip, a GUI with an edit field, or not echoing the characters at all. In the later case Input with option L2 gets the 2-letter commands in one step. (Of course, the MsgBoxes have to be replaced with your actual commands.)
~$LCtrl::

   If (A_ThisHotkey = A_PriorHotkey and A_TimeSincePriorHotkey < 300)

   {

      TrayTip,,Type your Command:

      Input k1, L1, {ESC}{Space} ; ESC, Space cancels

      IfEqual k1,, {

         TrayTip

         Return

      }

      TrayTip,,Type your Command: %k1%

      Input k2, L1, {ESC}{Space} ; other not visible keys ignored

      IfEqual k2,, {

         TrayTip

         Return

      }

      TrayTip,,Type your Command: %k1%%k2%

      k = %k1%%k2%

      IfEqual k, aa, MsgBox AA

      IfEqual k, az, MsgBox AZ

      IfEqual k, zz, MsgBox ZZ

      TrayTip

   }

Return


RatThing
  • Members
  • 3 posts
  • Last active: Aug 08 2005 11:28 AM
  • Joined: 05 Aug 2005

Now the task is: double tapping on the left Control key activates a hotstring-like functionality, but without the foreground application receiving the keystrokes.

Aha! Once again I am amazed by the versatility of this program and the helpfulness of the users on this forum. Thanks much for your assistance Laszlo — those are some pretty cool tricks.

I acknowledge that I could probably discover how to do these things with a lot of trial and error but it helps a lot to have examples I can use as a springboard.

Thanks again,

— Rat

toralf as guest
  • Guests
  • Last active:
  • Joined: --
Hi Rat,
I understand the wish for a springboard. And we are most happy to provide one. But at the end it is best to ask the right questions in the beginning.

From what I read in your last post. This should do the same thing:
^s::
  If GetKeyState("d")
     Run, https://signin.dell.com/premier/portal/login.aspx 
return

^q::
   If GetKeyState("q")
     Run, http://www.mapquest.com/ 
return
^x::
   If GetKeyState("e")
     Run, C:\Program Files\Outlook Express\msimn.exe 
return
Please press
Ctrl+d plus s
Ctrl+q plus q
Ctrl+e plus x
to execute.

timmymayes
  • Members
  • 6 posts
  • Last active: Oct 07 2009 06:25 AM
  • Joined: 28 Jun 2009
Just reading the forums and found a useful tip. Man i love auto hot key.