AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Entering commands using double-tapped Shift

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
RatThing



Joined: 05 Aug 2005
Posts: 3

PostPosted: Fri Aug 05, 2005 9:53 pm    Post subject: Entering commands using double-tapped Shift Reply with quote

(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
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4077
Location: Pittsburgh

PostPosted: Sat Aug 06, 2005 3:05 am    Post subject: Reply with quote

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.
Code:
~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
Back to top
View user's profile Send private message
toralf



Joined: 31 Jan 2005
Posts: 3841
Location: Bremen, Germany

PostPosted: Sat Aug 06, 2005 7:28 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Laszlo



Joined: 14 Feb 2005
Posts: 4077
Location: Pittsburgh

PostPosted: Sun Aug 07, 2005 2:18 am    Post subject: Reply with quote

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).
Back to top
View user's profile Send private message
Litmus Red



Joined: 25 Jul 2005
Posts: 139
Location: Richmond, Virginia

PostPosted: Sun Aug 07, 2005 2:51 am    Post subject: Reply with quote

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.

Code:
~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
Back to top
View user's profile Send private message
toralf



Joined: 31 Jan 2005
Posts: 3841
Location: Bremen, Germany

PostPosted: Sun Aug 07, 2005 7:56 am    Post subject: Reply with quote

Laszlo wrote:
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.autohotkey.com/forum/viewtopic.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:
Quote:
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
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Laszlo



Joined: 14 Feb 2005
Posts: 4077
Location: Pittsburgh

PostPosted: Sun Aug 07, 2005 3:15 pm    Post subject: Reply with quote

Thanks, toralf! I tried changing #MaxThreadsPerHotkey, as you suggest. It does allow simplifying the script (with the addition of Litmus Red):
Code:
#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.
Back to top
View user's profile Send private message
RatThing



Joined: 05 Aug 2005
Posts: 3

PostPosted: Mon Aug 08, 2005 2:52 am    Post subject: Reply with quote

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):

Code:
#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
Back to top
View user's profile Send private message
toralf



Joined: 31 Jan 2005
Posts: 3841
Location: Bremen, Germany

PostPosted: Mon Aug 08, 2005 4:39 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Laszlo



Joined: 14 Feb 2005
Posts: 4077
Location: Pittsburgh

PostPosted: Mon Aug 08, 2005 5:31 am    Post subject: Reply with quote

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.)
Code:
~$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
Back to top
View user's profile Send private message
RatThing



Joined: 05 Aug 2005
Posts: 3

PostPosted: Mon Aug 08, 2005 10:58 am    Post subject: Reply with quote

Laszlo wrote:
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
Back to top
View user's profile Send private message
toralf as guest
Guest





PostPosted: Mon Aug 08, 2005 11:21 am    Post subject: Reply with quote

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:
Code:
^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.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group