Jump to content

Script On/Script Off Function?


Yoshi
 Share

Recommended Posts

I have a script I wrote that has keys binded. The only problem is that when I need to type (chat or other things), I can't use those keys at all because pressing those keys activates the function it is binded to. Is there a way to make a hotkey to "unbind" all the other hotkeys, and same to "rebind" all the original hotkeys?

Here is what I simply have:

HotKeySet("v","appstart")

HotKeySet("z","appstop")

I'm looking for:

1) A function to "unbind" and "rebind" the letters "v" and "z" with a hotkey

or

2) A function to pause the entire script and to resume the entire script with a hotkey so that when the script is paused, I can use the letters "v" and "z" when typing

I couldn't seem to figure out how to do this through the manual (ehhh.... frustrating)

Thank you very much for your help

Link to comment
Share on other sites

There's the standard Pause function

Func _Pause()
    $Pause = Not $Pause
    While $Pause
        Sleep(10)
        TrayTip("","Script is paused.",3)
    WEnd

You could also check to see if the GUI is the active window and if not unset the hotkeys then reset them when it regains focus.

Link to comment
Share on other sites

Here's an example on how to set and unset hotkeys.

Kenny

HotKeySet("{F2}","HotKeyToggle")
Global $HotKey = 0
HotKeyToggle()

While 1
    Sleep(10)
WEnd

Func HotKey()
    MsgBox(0,"","Hot key pressed")
EndFunc

Func HotKeyToggle()
    If $HotKey = 1 Then
        HotKeySet("a");Unset
        HotKeySet("b");Unset
        $HotKey = 0
        MsgBox(0,"","Hotkeys off")
    ElseIf $HotKey = 0 Then
        HotKeySet("a","HotKey");Set
        HotKeySet("b","HotKey");Set
        $HotKey = 1
        MsgBox(0,"","Hotkeys on")
    EndIf
EndFunc
Edited by ken82m

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

Hey,

I found a nice way of doing this on the forum a while back (don't know who wrote the original)

Global Const $WM_ACTIVATEAPP = 0x001C
Global $AppTitle = "HotKey Active"

$hGUI = GUICreate("HotKey Active")
GUISetState()

_HotKeyActive()
GUIRegisterMsg($WM_ACTIVATEAPP, "_HotKeyActive")


While 1
    If GUIGetMsg() == -3 Then Exit
    Sleep(25)
WEnd


Func _HotKeyActive()
    If WinActive($AppTitle) Then ; if the window is active, set hotkeys
        HotKeySet("a","_A");Set
    Else ; if the window is not active, unset hotkeys
        HotKeySet("a");Unset
    EndIf
EndFunc

Func _A()
    MsgBox(64, 'HotKey', "Hotkeys are cool")
EndFunc
Edited by Robjong
Link to comment
Share on other sites

Thank you all for helping me out

I'm sure I will be able to implement one of these methods

You could also make the hotkeys be combinations that you wouldn't normally type, like Alt v and Alt z.
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

You could also make the hotkeys be combinations that you wouldn't normally type, like Alt v and Alt z.

yea, but I need some quick and easy one-hit hotkeys b/c I also make scripts for games like Counter-strike

ken82m's post seemed to work perfectly with a few personal tweaks

alt/ctrl/shift + key seems to work great but the keysticking gets a little irritating

I found this to prevent such incidents but I'm still a little confused on how to implement it

Func _SendEx($ss,$warn = "")
    Local $iT = TimerInit()
    While _IsPressed("10") Or _IsPressed("11") Or _IsPressed("12")
        if $warn <> "" and TimerDiff($iT) > 1000 Then
            MsgBox(262144, "Warning", $warn)
        EndIf
    sleep(50)
    WEnd
    Send($ss)
EndFunc
Link to comment
Share on other sites

Not sure myself. Can you give me a link to where you got it?

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

Okay i found it in the FAQ.

It's pretty simple, I didn't see the send command in the end of what you posted.

Add this to your code somehwere, usually at the end:

Func _SendEx($ss)
    Local $iT = TimerInit()
    
    While _IsPressed("10") Or _IsPressed("11") Or _IsPressed("12")
        If TimerDiff($iT) > 1000 Then
            MsgBox(262144, "Warning", "Shift, Ctrl and Alt Keys need to be released to proceed!")
        EndIf
    WEnd
    Send($ss)
EndFunc;==>_SendEx

Now anywhere for your hotkey functions anywhere your using for example

Send("{CTRL}a")

Use this instead

_SendEx("{CTRL}a")

Give it a try, but your probably going to want to do something other than that MsgBox for games

-Kenny

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

Okay i found it in the FAQ.

It's pretty simple, I didn't see the send command in the end of what you posted.

Add this to your code somehwere, usually at the end:

Func _SendEx($ss)
    Local $iT = TimerInit()
    
    While _IsPressed("10") Or _IsPressed("11") Or _IsPressed("12")
        If TimerDiff($iT) > 1000 Then
            MsgBox(262144, "Warning", "Shift, Ctrl and Alt Keys need to be released to proceed!")
        EndIf
    WEnd
    Send($ss)
EndFunc;==>_SendEx

Now anywhere for your hotkey functions anywhere your using for example

Send("{CTRL}a")

Use this instead

_SendEx("{CTRL}a")

Give it a try, but your probably going to want to do something other than that MsgBox for games

-Kenny

alright, thnx

seems to work fine

Link to comment
Share on other sites

great, have fun :)

Kenny

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

If the script you're making is only going to affect counter-strike, I'd use something like this:

HotKeySet("z", "_HandleHotkeys")
HotKeySet("x", "_HandleHotkeys")

While 1
    Sleep(2500)
WEnd

Func _HandleHotkeys()
    HotKeySet(@HotKeyPressed)
    
    If WinActive("[CLASS:Valve001]") Then
        Switch @HotKeyPressed
            Case "z"
            ; do something on z
            Case "x"
            ; do something on x
        EndSwitch
    Else
        Send(@HotKeyPressed)
    EndIf
    
    HotKeySet(@HotKeyPressed, "_HandleHotkeys")
    
EndFunc

Quite self-explanatory, it first unbinds the key(read later why), checks if the cs window is active(or any other hl1 based game), if it is, runs the desired code, otherwise,

it sends the key you pressed(reason for unbinding it first), then it rebinds the key.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...