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 

Disable a section of a script

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



Joined: 03 Oct 2005
Posts: 186

PostPosted: Sun Jul 22, 2007 3:34 am    Post subject: Disable a section of a script Reply with quote

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.
Back to top
View user's profile Send private message
Dewi Morgan



Joined: 03 Oct 2005
Posts: 186

PostPosted: Sun Jul 22, 2007 5:10 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Superfraggle



Joined: 02 Nov 2004
Posts: 1019
Location: London, UK

PostPosted: Sun Jul 22, 2007 7:11 am    Post subject: Reply with quote

how about using the hotkey command to turn off the keys.
_________________
Steve F AKA Superfraggle

http://r.yuwie.com/superfraggle
Back to top
View user's profile Send private message MSN Messenger
Micahs



Joined: 01 Dec 2006
Posts: 460

PostPosted: Sun Jul 22, 2007 10:57 am    Post subject: Reply with quote

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.
_________________
Back to top
View user's profile Send private message
Dewi Morgan



Joined: 03 Oct 2005
Posts: 186

PostPosted: Sun Jul 22, 2007 12:45 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Micahs



Joined: 01 Dec 2006
Posts: 460

PostPosted: Sun Jul 22, 2007 1:01 pm    Post subject: Reply with quote

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)
_________________
Back to top
View user's profile Send private message
Helpy
Guest





PostPosted: Mon Jul 23, 2007 11:56 am    Post subject: Reply with quote

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... Smile
Back to top
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