AutoHotkey Community

It is currently May 26th, 2012, 9:21 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: July 29th, 2009, 7:16 pm 
Offline

Joined: July 29th, 2009, 7:09 pm
Posts: 2
Location: Minnesota
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?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 29th, 2009, 8:01 pm 
Offline

Joined: May 22nd, 2006, 2:12 pm
Posts: 150
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 29th, 2009, 9:19 pm 
Code:
~4 & 3::
GetKeyState, OutputVar, alt
if OutputVar = D
msgbox, 3 keys are pressed
return


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 30th, 2009, 12:30 am 
Offline

Joined: July 9th, 2009, 1:13 am
Posts: 140
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


Report this post
Top
 Profile  
Reply with quote  
PostPosted: July 30th, 2009, 9:13 am 
Offline

Joined: December 20th, 2005, 4:15 am
Posts: 165
Location: Malaysia
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 30th, 2009, 10:25 am 
Offline

Joined: November 7th, 2006, 9:47 pm
Posts: 1934
Location: Germany
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 30th, 2009, 11:03 am 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
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 FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, wolverineks and 66 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group