Sign in to follow this  
Followers 0
waynew

how to start/stop a function use the same key(about HotKey.au3)

5 posts in this topic

#1 ·  Posted (edited)

#Include <HotKey.au3>

Global Const $VK_ESCAPE = 0x1B
Global Const $VK_F12 = 0x7B
Global $testFlg

_HotKeyAssign($VK_F12, 'test', $HK_FLAG_DEFAULT)

; Assign "CTRL-ESC" with Quit()
_HotKeyAssign(BitOR($CK_CONTROL, $VK_ESCAPE), 'Quit')

While 1
    Sleep(10)
WEnd

Func Quit()
    Exit
EndFunc   ;==>Quit


Func test()
    $testFlg = Not $testFlg
    If Not $testFlg Then Beep()
    Local $io = 0
    While $testFlg
        Sleep(1000)
        $io += 1
        ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $io = ' & $io & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
    WEnd
EndFunc

i want to start or stop the function "test" use the same key ,but it seemed don't work,what's wrong.

HotKey.au3

Edited by waynew

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Ensure the func test() ends to be able to fire it again with the same HotKey and do the testing for $testFlg in the mainloop.

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

@waynew

Your code design is wrong. You should not stop the interrupting function - Test(). Here's one way to fix this.

#Include <HotKey.au3>

Global Const $VK_ESCAPE = 0x1B
Global Const $VK_F12 = 0x7B

Global $testFlg = False, $io

_HotKeyAssign($VK_F12, 'Test', $HK_FLAG_NOOVERLAPCALL)
_HotKeyAssign(BitOR($CK_CONTROL, $VK_ESCAPE), 'Quit')

While 1
    Sleep(10)
WEnd

Func Quit()
    Exit
EndFunc   ;==>Quit

Func Test()
    $testFlg = Not $testFlg
    If $testFlg Then
        $io = 0
        AdlibRegister('Debug', 1000)
    Else
        AdlibUnRegister('Debug')
        Beep()
    EndIf
EndFunc   ;==>Test

Func Debug()
    $io += 1
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $io = ' & $io & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
EndFunc   ;==>Debug

Share this post


Link to post
Share on other sites

from the helpfile

; Press Esc to terminate script, Pause/Break to "pause"

Global $Paused
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")
HotKeySet("+!d", "ShowMessage")  ;Shift-Alt-d

;;;; Body of program would go here ;;;;
While 1
    Sleep(100)
WEnd
;;;;;;;;

Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc

Func Terminate()
    Exit 0
EndFunc

Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Share this post


Link to post
Share on other sites

thanks a lot

but i want to use the function _HotKeyAssign,i think there should be a way to solve this.

Share this post


Link to post
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
Sign in to follow this  
Followers 0