Jump to content

can hotKeySet cause exit, retrun or break


itaipee
 Share

Recommended Posts

Hi

I have gui aplication in Autoit

I want to ahve hotkey which will used to stop the operation.

Let say I'm useing inside Function 'func1' ,hotKeySet("^P","Func2")

what I need to do in Func2 to cause Func1 return or break. ( exit I can by exit)

thanks

Link to comment
Share on other sites

Func Function1()
    HotKeySet("^p", "Function2")
    ;; Do whatever you want in here
    HotKeySet("^p", "")
EndFunc

Func Function2()
    Exit
EndFunc

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

I want that the code will break lop or return from a function with certain value

Exit is not good - it terminate the entire program

Func Function1()
    HotKeySet("^p", "Function2")
    $flag = 1
    while ( $falg == 1) 
    ;; Do whatever you want in here
     ;;
     ;; I Want that Function2 will somehow send 'break' or cause the lop to end    - or even the function to return with some status
     ;;  'exit' is not good  - it terminate the entrire program. 
    Wend
    HotKeySet("^p", "")
EndFunc

Func Function2()
    ????
EndFunc
Link to comment
Share on other sites

I want that the code will break lop or return from a function with certain value

Exit is not good - it terminate the entire program

Func Function1()
 HotKeySet("^p", "Function2")
 $flag = 1
 while ( $falg == 1) 
 ;; Do whatever you want in here
 ;;
 ;; I Want that Function2 will somehow send 'break' or cause the lop to end - or even the function to return with some status
 ;; 'exit' is not good - it terminate the entrire program. 
 Wend
 HotKeySet("^p", "")
EndFunc

Func Function2()
 ????
EndFunc

Geosoft has just about handed you the solution on a plate :). The hotkey can set a global variable in the function it calls and he has even given you the $flag variable to use. All you need to do is to make sure that $flag is global and set it in the hotkey function.

Global $flag

Func Function1()
 HotKeySet("^p", "Function2")
 $flag = 1
 while ( $flag == 1) 
 ;; Do whatever you want in here
 
 Wend
 HotKeySet("^p", "")
EndFunc

Func Function2()
 $flag = 0
EndFunc
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

Geosoft has just about handed you the solution on a plate :). The hotkey can set a global variable in the function it calls and he has even given you the $flag variable to use. All you need to do is to make sure that $flag is global and set it in the hotkey function.

Global $flag

Func Function1()
 HotKeySet("^p", "Function2")
 $flag = 1
 while ( $flag == 1) 
 ;; Do whatever you want in here
 
 Wend
 HotKeySet("^p", "")
EndFunc

Func Function2()
 $flag = 0
EndFunc

First , that is much better solution , thanks

Second , let make the problem a bit harder..

I want to exit the lop - in the minute the hotkey was pressed - and not only in the beggining of the lop

the global flag is good and elegant when I have one simple command . but if the proccess is more complecated then I need to had "if ($flag == 1)" before each command or at list before each major command ( for example in command 3 )

When the program is become long and complicate the flag is not such nice solution

Global $flag

Func Function1()
 HotKeySet("^p", "Function2")
 $flag = 1
 while ( $flag == 1) 
 ;;set of commands 1
;;set of commands 2
if ( $flag == 1) then
   ;;set of commands 3   ;; that ugly 
Endif
;;set of commands 4
 
 Wend
 HotKeySet("^p", "")
EndFunc

Func Function2()
 $flag = 0
EndFunc
Link to comment
Share on other sites

  • 2 weeks later...

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...