AutoHotkey Community

It is currently May 25th, 2012, 12:09 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: July 22nd, 2007, 4:34 am 
Offline

Joined: October 3rd, 2005, 2:42 am
Posts: 186
I am sure that many moons ago I used a command to disable certain sections of a script... I may be getting confused with mIRC script, though, I guess.

Is it possible to suspend only a certain subset of hotkeys/hotstrings/whatever?

_________________
Yet another hotkeyer.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 22nd, 2007, 6:10 am 
Offline

Joined: October 3rd, 2005, 2:42 am
Posts: 186
The reason I ask this is because I have a script which makes WASD keys act as cursors, in the Sherwood MMO, and I want it to toggle to act normally for chat.

At the moment I have it running as a separate script, and hotkey it to suspend. Which works OK, but I want to include it from a larger script, and suspend only this part.

Essentially, I want a #if... and the only AHK #if commands are #IfWinActive and #IfWinExist. These do not accept variables, because they're preprocessor things. They do accept WindowGroups, though.

WindowGroups COULD be used as a toggle, by adding/removing the relevant window from them... if windowGroups could have entries removed from them - but though there's GroupAdd, there's no GroupRemove. Chris writes:
Quote:
There's currently no way to do it, so the usual work-around would be to create a new group. Each group takes up very little memory, so that won't be a concern for most usages.


I tried to use a window as the "flag variable", like...

Code:
; Script Function:
;   Example block-toggler (non-working)
;   Enables the wasd keys in the Sherwood MMORPG. Toggle them on and
;   off with ScrollLock, NumLock or PrintScreen.
; BUG:
;   Does not turn off aliases when changing windows.
; License:
;   This code is explicitly released to the public domain under the "code
;   sample" precedent. You may modify, reuse or relicence it in any way
;   without informing or attributing me. Truly free, not just "Free(tm)".
#AllowSameLineComments
#InstallKeybdHook
#NoEnv ; For security
#Persistent
#SingleInstance force
DetectHiddenWindows on
SendMode Input
return

#IfWinActive MMORPG in Sherwood
ScrollLock::
NumLock::
PrintScreen::
IfWinExist wasd2uldr
{
  Gui destroy
}
else {
  Gui, Add, Text,, Window for toggling the wasd2uldr block
  Gui show, hide , wasd2uldr
  DetectHiddenWindows on
}
return

#IfWinExist wasd2uldr
$*w::Send {up down}
$*w up::Send {up up}
$*a::Send {left down}
$*a up::Send {left up}
$*s::Send {down down}
$*s up::Send {down up}
$*d::Send {right down}
$*d up::Send {right up}

#IfWinExist
#IfWinActive



This ALMOST works... except that the #IfWinActive is overridden by the #IfWinExist. So alt-tabbing or moving away from the window while the wasd aliases are active would be really annoying.

_________________
Yet another hotkeyer.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 22nd, 2007, 8:11 am 
Offline

Joined: November 2nd, 2004, 2:43 pm
Posts: 1019
Location: London, UK
how about using the hotkey command to turn off the keys.

_________________
Steve F AKA Superfraggle

http://r.yuwie.com/superfraggle


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 22nd, 2007, 11:57 am 
Offline

Joined: December 1st, 2006, 9:27 am
Posts: 460
My thoughts exactly:
Code:
#AllowSameLineComments
#InstallKeybdHook
#NoEnv ; For security
#Persistent
#SingleInstance force
DetectHiddenWindows on
SendMode Input
SetTitleMatchMode,2
hotkeys("Off")   ;turn off hotkeys by default
SetTimer,CheckState,500
return

CheckState:
   IfWinNotActive, MMORPG in Sherwood
   {   hotkeys("Off")
      Return
   }
   If(keyState)
   {   hotkeys("On")
   }
   Else
   {   hotkeys("Off")
   }
Return

#IfWinActive, MMORPG in Sherwood
ScrollLock::
NumLock::
PrintScreen::
   keyState := !keyState
return
#IfWinActive

hotkeys(onORoff)
{
   Hotkey,$*w,      %onORoff%
   Hotkey,$*w up,   %onORoff%
   Hotkey,$*a,      %onORoff%
   Hotkey,$*a up,   %onORoff%
   Hotkey,$*s,      %onORoff%
   Hotkey,$*s up,   %onORoff%
   Hotkey,$*d,      %onORoff%
   Hotkey,$*d up,   %onORoff%
}

$*w::Send {up down}
$*w up::Send {up up}
$*a::Send {left down}
$*a up::Send {left up}
$*s::Send {down down}
$*s up::Send {down up}
$*d::Send {right down}
$*d up::Send {right up}

I tested it with notepad and it seemed to work like you wanted. When the desired window is not active it deactivates the hotkeys and remembers the current state, restoring it when the window is active again. You can toggle the state only when the window is active.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 22nd, 2007, 1:45 pm 
Offline

Joined: October 3rd, 2005, 2:42 am
Posts: 186
THANK you! :) That's exactly the function I was looking for, but after fruitlessly searching for things like "disable" and "toggle", I had convinced myself I must be thinking of some other language.

Hrm... though it solves my immediate problem, does it work for things other than hotkeys? Like, hotstrings, timers, etc? I may at some point want to disable a whole chunk of code, not just the hotkeys within it.

_________________
Yet another hotkeyer.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 22nd, 2007, 2:01 pm 
Offline

Joined: December 1st, 2006, 9:27 am
Posts: 460
You can create context sensitive hotstrings (just like hotkeys) using #ifwinactive or disable all hotstrings and hotkeys using suspend. But as far as disabling certain hotstrings, I don't think so.

Timers: Settimer,mytimer,off (or on)

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 23rd, 2007, 12:56 pm 
In SciTE, select the section to disable, hit Ctrl+Q, it will start each selected line with ;~ disabling them... The same command restore the lines. The tilde is to distinguish such disabling from regular comments, to ease toggling.
You can also write a small script taking a script as input, and a list of line offsets, and doing the same thing... :)


Report this post
Top
  
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: cmikaiti, Exabot [Bot], hcx37b, KenC, Maestr0, TedStriker, Tegno, tomL, Yahoo [Bot] and 48 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