 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
victorzale
Joined: 29 Jul 2009 Posts: 2 Location: Minnesota
|
Posted: Wed Jul 29, 2009 6:16 pm Post subject: How do I create a hotkey using 3 keys? |
|
|
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 |
|
 |
john tuomi
Joined: 22 May 2006 Posts: 150
|
Posted: Wed Jul 29, 2009 7:01 pm Post subject: |
|
|
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 |
|
 |
Guest
|
Posted: Wed Jul 29, 2009 8:19 pm Post subject: |
|
|
| 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
|
Posted: Wed Jul 29, 2009 11:30 pm Post subject: |
|
|
| 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 |
|
 |
Lemming
Joined: 20 Dec 2005 Posts: 165 Location: Malaysia
|
Posted: Thu Jul 30, 2009 8:13 am Post subject: It's a variation of start-stop hotkey |
|
|
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 |
|
 |
Tuncay
Joined: 07 Nov 2006 Posts: 1886 Location: Germany
|
Posted: Thu Jul 30, 2009 9:25 am Post subject: |
|
|
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 |
|
 |
SoLong&Thx4AllTheFish
Joined: 27 May 2007 Posts: 4999
|
Posted: Thu Jul 30, 2009 10:03 am Post subject: |
|
|
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 |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|