AutoHotkey Community

It is currently May 27th, 2012, 6:59 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: March 6th, 2006, 12:47 am 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
It was asked several times. Here is a solution based on #IfWinExist. Some hotkey routines will activate groups of other hotkeys via creating/destroying hidden windows.

Below is an example with toggles ScrollLock and Alt-T. The ScrollLock hotkey routine checks the toggle state of ScrollLock. If it is On, create a hidden GUI window, named "ScrLk". If it is Off, destroy this invisible window. (Similarly, you can use CapsLock and NumLock.) Alt-T toggles a variable and creates/destroys another hidden window, named Alt-T. (Other non-toggle keyboard keys can be used similarly.)

These hidden windows only exist when the corresponding toggle is On, so the hotkeys after the corresponding #IfWinExist lines only work if they are turned On. (The first listed hotkey is activated if more than one toggle is On.) After the last #IfWinExist line list the hotkeys, which shall be active when no toggle condition is active.
Code:
DetectHiddenWindows On

GoSub ~ScrollLock ; react to initial state
; ... further code here

; --- end of autoexecute section ---

~ScrollLock::     ; toggle by create/destroy a hidden window
   If GetKeyState("ScrollLock","T")
      Gui 1:Show, Hide, ScrLk
   Else
      Gui 1:Destroy
Return

!T::              ; toggle by create/destroy a hidden window
   AltT := !AltT
   If AltT
      Gui 2:Show, Hide, Alt-T
   Else
      Gui 2:Destroy
Return

#IfWinExist ScrLk ; below the HotKeys are active when CapsLock is ON
!z::MsgBox ScrollLock ON
;...

#IfWinExist Alt-T ; below the HotKeys are active when Alt-T toggle is ON
!z::MsgBox Alt-T ON
;...

#IfWinExist       ; below the HotKeys are active when all toggles are Off
!z::MsgBox ScrollLock/Alt-T Off
;...
Edit 2006.03.07: Added comments, changed GoTo to GoSub


Last edited by Laszlo on September 22nd, 2006, 3:54 am, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 7th, 2006, 5:11 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
It's a novel idea to have a different set of hotkeys active depending on the state of Numlock or ScrollLock. Even better, you've given us an easy framework to do it. Thanks.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 7th, 2006, 5:37 pm 
Hi Laszlo. Just a newbie question. In
Laszlo wrote:
Code:
DetectHiddenWindows On
GoTo ~ScrollLock  ; react to initial state

~ScrollLock::     ; toggle by create/destroy a hidden window
;....
;...
, why Goto to a label witch is just below ? What is the utility ? Thanks


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 7th, 2006, 5:52 pm 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
This is not a label, but a hotkey (callable like a label).
The autoexecute section stops just before this hotkey.
So, to execute this part of the script, you have to go to it explicitely.

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 7th, 2006, 6:47 pm 
OK PhiLho, thanks a lot for the explanation.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 7th, 2006, 8:46 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
I added comments to the original post, to clarify this. If the ScrollLock toggle activation is not the last autoexecute instruction, you have to change GoTo to GoSub, calling directly the hotkey subroutine. It is also less confusing.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 22nd, 2009, 4:49 pm 
Offline

Joined: January 10th, 2009, 1:34 pm
Posts: 135
Location: Virginia
I have something working... almost....

Code:
;******************* CapsLock and NumLock experiement number 2 ********************
CLstate := GetKeyState("Capslock", "T")
NLstate := GetKeyState("NumLock", "T")

~CapsLock:: CLstate := GetKeyState("Capslock", "T")  ; True if CapsLock is ON, false otherwise.
~NumLock:: NLstate := GetKeyState("NumLock", "T") ; add the NumLock status; CapsLock navigation

; Implement some sort of hotkey trap based on the state of the caps and nums both 0
; in that situation the hotkey is not a hotkey.

$z::
loop
   {
   
      if ((CLstate = 0) & (NLstate = 0)) ; Send normal key function if both off
      {
         Send {~z} ; How do I get this to pass without triggering the hotkey again.
         MsgBox, 4, ,CAPS %CLstate% + NL %NLstate%, 1
         break
      }
      else if ((CLstate = 1) & (NLstate =0)) ; 2 caps only
      {   
         Send {2}
         MsgBox, 4, ,CAPS %CLstate% + NL %NLstate%, 1
         break
      }
   
      else if ((CLstate = 0) & (NLstate = 1)) ; 3 numlock is only 
      {
         Send {3}
         MsgBox, 4, ,CAPS %CLstate% + NL %NLstate%, 1
         break
      }
      else if ((CLstate = 1) & (NLstate = 1)) ; 4 both off
      {   
         Send {4}
         MsgBox, 4, ,CAPS %CLstate% + NL %NLstate%, 1
         return
      }
      
   }
return


I suppose I could make some sort of if then before the hotkey, hmm.....

Please consider and advise.

Thanks!

_________________
KeyMce/GenMce - mackie emulator for pc keyboard/Convert your controller to mackie.
Midi I/O - Want to play with midi/ahk?


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: No registered users and 17 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