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 

How do I create a hotkey using 3 keys?

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



Joined: 29 Jul 2009
Posts: 2
Location: Minnesota

PostPosted: Wed Jul 29, 2009 6:16 pm    Post subject: How do I create a hotkey using 3 keys? Reply with quote

I apologize if this is a totally noob question, but what I wanted to setup is a way to use numbered Hotkeys, for a range of tasks from 0-100.

For task# 43, I want to use a hotkey of Alt plus #4, plus #3, so that I can easily associate the task with the right macro. (using the upper Number keys or the Numpad).

Can anyone assist?
Back to top
View user's profile Send private message
john tuomi



Joined: 22 May 2006
Posts: 150

PostPosted: Wed Jul 29, 2009 7:01 pm    Post subject: Reply with quote

I don' t think that you can use multiple keys to launch the hot key, but you might be able to do it like this:
Code:

::43::!a
::44::!b

!a::
send,1{enter};you would enter whatever you would want Autohotkey to do
return

!b::
send,2{enter}};you would enter whatever you would want Autohotkey to do
return



In this way, the string replace (43 or 44 in the sequence above), would launch the desired shortkey. You would probably want to put in an IFWinActive statement to keep this from happening if the desired window is not active.
Back to top
View user's profile Send private message
Guest






PostPosted: Wed Jul 29, 2009 8:19 pm    Post subject: Reply with quote

Code:
~4 & 3::
GetKeyState, OutputVar, alt
if OutputVar = D
msgbox, 3 keys are pressed
return
Back to top
Tyrsius



Joined: 09 Jul 2009
Posts: 140

PostPosted: Wed Jul 29, 2009 11:30 pm    Post subject: Reply with quote

john tuomi wrote:
I don' t think that you can use multiple keys to launch the hot key, but you might be able to do it like this:
Code:

::43::!a
::44::!b

!a::
send,1{enter};you would enter whatever you would want Autohotkey to do
return

!b::
send,2{enter}};you would enter whatever you would want Autohotkey to do
return



In this way, the string replace (43 or 44 in the sequence above), would launch the desired shortkey. You would probably want to put in an IFWinActive statement to keep this from happening if the desired window is not active.


This is uneccesary. You could just use the string replace to execute the !a thread.
Code:

::43::
send,1{enter};you would enter whatever you would want Autohotkey to do
return
Back to top
View user's profile Send private message
Lemming



Joined: 20 Dec 2005
Posts: 165
Location: Malaysia

PostPosted: Thu Jul 30, 2009 8:13 am    Post subject: It's a variation of start-stop hotkey Reply with quote

I initially thought this was a trivial problem, but later realised it wasn't so straightforward.

It is actually a variation of the "stop repeating action without exiting the script" problem as mentioned in the FAQ:

http://www.autohotkey.com/docs/FAQ.htm#repeat

At some point, for example, you may want to press Alt-11 or Alt-33, which is actually Alt-1 twice in a row, or Alt-3 twice in a row.

With that in mind, I've modified the FAQ script to handle all double-press alt combinations for 2, 3, and 4. Launch the script, and try pressing Alt-42, Alt-23, Alt-33, etc.

Unfortunately, this is an "exponential" solution, so if you want to handle all 10 digits, the script will have be much longer.

Code:
;
; AutoHotkey Version: 1.x
; Language:       English
; Platform:       WinXP/Vista
; Author:         Lemming
;
; Script Function:
;   Template script (you can customize this template by editing "ShellNew\Template.ahk" in your Windows folder)
;

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

; Alt-2

#MaxThreadsPerHotkey 3
!2::
#MaxThreadsPerHotkey 1
If Alt2BeingPressed
{
   MsgBox,Alt-2-2 was pressed!
   Alt2BeingPressed:= false  ; Signal that thread's loop to stop
    return  ; End this thread so that the one underneath will resume and see the change made by the line above.
}
If Alt3BeingPressed
{
   MsgBox,Alt-3-2 was pressed!
   Alt2BeingPressed:= false  ; Signal that thread's loop to stop
   Alt3BeingPressed:= false  ; Signal that thread's loop to stop
    return  ; End this thread so that the one underneath will resume and see the change made by the line above.
}
If Alt4BeingPressed
{
   MsgBox,Alt-4-2 was pressed!
   Alt2BeingPressed:= false  ; Signal that thread's loop to stop
   Alt4BeingPressed:= false  ; Signal that thread's loop to stop
    return  ; End this thread so that the one underneath will resume and see the change made by the line above.

}
; Otherwise:
Alt2BeingPressed := true
Loop, 10
{
Sleep 50
if not Alt2BeingPressed
   break
}
Alt2BeingPressed:= false ; Reset in preparation for the next press of this hotkey.
Return

; Alt-3

#MaxThreadsPerHotkey 3
!3::
#MaxThreadsPerHotkey 1
If Alt2BeingPressed
{
   MsgBox,Alt-2-3 was pressed!
   Alt2BeingPressed:= false  ; Signal that thread's loop to stop
   Alt3BeingPressed:= false  ; Signal that thread's loop to stop
    return  ; End this thread so that the one underneath will resume and see the change made by the line above.
}
If Alt3BeingPressed
{
   MsgBox,Alt-3-3 was pressed!
   Alt3BeingPressed:= false  ; Signal that thread's loop to stop
    return  ; End this thread so that the one underneath will resume and see the change made by the line above.
}
If Alt4BeingPressed
{
   MsgBox,Alt-4-3 was pressed!
   Alt3BeingPressed:= false  ; Signal that thread's loop to stop
   Alt4BeingPressed:= false  ; Signal that thread's loop to stop
    return  ; End this thread so that the one underneath will resume and see the change made by the line above.

}
; Otherwise:
Alt3BeingPressed := true
Loop, 10
{
Sleep 50
if not Alt3BeingPressed
   break
}
Alt3BeingPressed:= false ; Reset in preparation for the next press of this hotkey.
Return

; Alt-4

#MaxThreadsPerHotkey 3
!4::
#MaxThreadsPerHotkey 1
If Alt2BeingPressed
{
   MsgBox,Alt-2-4 was pressed!
   Alt2BeingPressed:= false  ; Signal that thread's loop to stop
   Alt4BeingPressed:= false  ; Signal that thread's loop to stop
    return  ; End this thread so that the one underneath will resume and see the change made by the line above.
}
If Alt3BeingPressed
{
   MsgBox,Alt-3-4 was pressed!
   Alt3BeingPressed:= false  ; Signal that thread's loop to stop
   Alt4BeingPressed:= false  ; Signal that thread's loop to stop
    return  ; End this thread so that the one underneath will resume and see the change made by the line above.

}
If Alt4BeingPressed
{
   MsgBox,Alt-4-4 was pressed!
   Alt4BeingPressed:= false  ; Signal that thread's loop to stop
    return  ; End this thread so that the one underneath will resume and see the change made by the line above.
}
; Otherwise:
Alt4BeingPressed := true
Loop, 10
{
Sleep 50
if not Alt4BeingPressed
   break
}
Alt4BeingPressed:= false ; Reset in preparation for the next press of this hotkey.
Return
Back to top
View user's profile Send private message
Tuncay



Joined: 07 Nov 2006
Posts: 1886
Location: Germany

PostPosted: Thu Jul 30, 2009 9:25 am    Post subject: Reply with quote

Here is my quick solution. Tested and it works:

Code:
SendMode, Input
#NoEnv

#4::
KeyWait, 3, DT3
If ErrorLevel = 0
    GoSub, Hotkey_Win_4_3
Return

#3::
KeyWait, 4, DT3
If ErrorLevel = 0
    GoSub, Hotkey_Win_4_3
Return

Hotkey_Win_4_3:
Send, Hotkey_Win_4_3
Return


May be it is possible to make a function to create dynamically these hotkeys.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
SoLong&Thx4AllTheFish



Joined: 27 May 2007
Posts: 4999

PostPosted: Thu Jul 30, 2009 10:03 am    Post subject: Reply with quote

This requires some more work but I suspect Input might be of use here
Code:
Loop, 99
   MatchList .= A_Index ","
Input, OutputVar, L2, , MatchList
Gosub, Label%OutputVar%
Return

Label12:
MsgBox 12
Return

Label25:
MsgBox 25
Return
Run script type 12 or 25 (others will give error)
It only works with 2 digits unless you introduce EndChars? (like space or alt UP?)

Now what needs to be added is a check that the input will only "listen" for digits when the ALT is pressed down but I leave that for someone else to solve.
_________________
AHK Wiki FAQ
TF : Text files & strings lib, TF Forum
Back to top
View user's profile Send private message
Display posts from previous:   
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