Jump to content

If condition check in a interruptible function. Is it safe?


Go to solution Solved by JohnOne,

Recommended Posts

Let start with some examples:

1. (As seen in another topic: '?do=embed' frameborder='0' data-embedContent>> ).

Script copied from that topic

Interrupt function can be any hotkey/event/adlib/callback.

If-check inside interrupted function/script 

; HotKeySet, or any function that can cause script interrupt
HotKeySet("{Delete}", "RemoveSelectedControl")

;...
Dim $InfoAboutControls[4096]
Global $HandleForCurrentControl
;...


While 1
    $msg = GuiGetMsg()
  ;....
    
  ;---Code to process moving a control (drag-n-drop)---
    ; If check in MAIN LOOP (interruptible function).
    If $HandleForCurrentControl > 0 Then;Make sure we have a valid control handle
  ; ***** oops user pressed Delete key and we get pre-empted
  ; ***** user removed the selected control.
  ; ***** Returning from the RemoveSelectedControl function and resuming here:
        GuiCtrlSetPos($InfoAboutControls[$HandleForCurrentControl], $newLeftPosition, $newTopPosition)
    EndIf
WEnd

Func RemoveSelectedControl()
    $HandleForCurrentControl = -1
EndFunc

2. If-check inside interrupt function

Hotkey only.

Flag is set right after if check.

It's possible or not this function print twice or more?

HotKeySet("{Delete}", "_TestHotkey")

Func _TestHotkey()
  Static $bFlag = True
  If ($bFlag) Then 
     ; ***** Right here, user pressed Delete key
     ; ***** bFlag is currently not set
     ; ***** And the script will execute this function twice or more times, instead of just once
     $bFlag = False
     ConsoleWrite("This should be printed only ONCE")
  EndIf
EndFunc

3. Same as 2, but with global flag

The question is: can I rely on if-checking with a flag, to ensure that my script doesn't do any strange things, as describe in the above examples?

Edited by binhnx

99 little bugs in the code

99 little bugs!

Take one down, patch it around

117 little bugs in the code!

Link to post
Share on other sites

Not a specific script. That is only a general problem, and I ask for a general answer.

Indeed, 3 above examples is details as much as it should. Any line added to that is for nothing but make the topic unfocused.

To provide more details, 

  • Details about example 1 can be read in the original topic linked.
  • For example 2 and 3: As you see, my script only allow _TestHotkey() function to execute exactly once. But since AutoIt script can be interrupted and reentrant, it's probably that function be executed twice or more, if user presses "Delete" key right after the if-check line is executed. So, I need an assurance that AutoIt "had some mechanism" to play with it, like a Critical Section as describe at the linked topic.

99 little bugs in the code

99 little bugs!

Take one down, patch it around

117 little bugs in the code!

Link to post
Share on other sites

There is almost no possibility of that function running twice if you clear the hotkey/adlib function used to call it as the very first line of the function.

HotKeySet("{Delete}", "_TestHotkey")

Func _TestHotkey()
  HotKeySet("{Delete}")
  Static $bFlag = True
  If ($bFlag) Then 
     ; ***** Right here, user pressed Delete key
     ; ***** bFlag is currently not set
     ; ***** And the script will execute this function twice or more times, instead of just once
     $bFlag = False
     ConsoleWrite("This should be printed only ONCE")
  EndIf
EndFunc

If you wanted the HotKey to be active again, you'd need to set it again somewhere else in the script. AdlibUnRegister would work the same way.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to post
Share on other sites

Or:

$bFlag = True
HotKeySet("{Delete}", "_TestHotkey")

Func _TestHotkey()
  If $bFlag Then 
     ; ***** Right here, user pressed Delete key
     ; ***** bFlag is currently not set
     ; ***** And the script will execute this function twice or more times, instead of just once
     $bFlag = False
     ConsoleWrite("This should be printed only ONCE")
  EndIf
EndFunc

While True
WEnd
Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to post
Share on other sites

@BrewmanNH: yeah, in your case, if Delete is pressed right at the function begining, before the HotKeySet line, so what will happen?

In general, it also very very low probability, but i need to an exactly zero. 

Indeed, with Hotkey, if a line is the smallest element in AutoIt, so interrupt a line never can occur, so another trick will be better:

Func _TestHotKey()
 Static $nCounter = 0
 $nCounter += 1
 If ($nCounter = 1) Then
  ;Do everything you want
 EndIf
 $nCounter -= 1
EndFunc

It guarantee that the function execute exactly once (at the same time). But this method cannot be used with event or adlib since all that is queued, not interruped & reentrant.

@jdelaney: It's exactly my example 3. It's still unsafe at all, unless a dev state that it's safe!

A side note: The set flag statement is right after the check statement. I wonder AutoIt has some guard around it, or it's still simply a race-condition problem.

Edited by binhnx

99 little bugs in the code

99 little bugs!

Take one down, patch it around

117 little bugs in the code!

Link to post
Share on other sites

There's probably a .000000000000000000000000001% chance that someone could hit the same key twice in the time it takes to get to that line. There's no such thing as exactly zero in computers, you are NEVER going to achieve that, especially in an interpreted language.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to post
Share on other sites

@BrewmanNH.

No, as seen in the linked topic: '?do=embed' frameborder='0' data-embedContent>>

If a Critical Section (or any other guards) is implemented, it should be exactly zero!

The linked topic is provide a little information so I do not know it is implemented or not, so I open this topic to ask.

A side note: Computing is all about zero and one, isn't it?

99 little bugs in the code

99 little bugs!

Take one down, patch it around

117 little bugs in the code!

Link to post
Share on other sites

We're talking about timing, not numbers. Also, if you had read the first response to that nearly 10 year old thread, the answer given is exactly what I proposed.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to post
Share on other sites

Yeah, just kidding :)

I've read, and notice that, but after search along the forum, no other topic describe that problem, so I haven't know about its state yet.

In computing, many method is implemented to ensure that everything is done right. In a general programming language, also count interpreted language, such as Python or PHP also implemented that, using a lock before the check and the problem solved.

Is AutoIt (internally) did that?

Edit: Maybe I mis-understood what the Overlord said? Did he said that the guard function is totally imlemented? Or totally ignored? Or he said that the guard function is implemented around the disable Hotkey/Adlib/OnEvent function? 

Edited by binhnx

99 little bugs in the code

99 little bugs!

Take one down, patch it around

117 little bugs in the code!

Link to post
Share on other sites

There is no guard function, you'd have to program that yourself, and it's all about disabling the hotkey or adlib as soon as you enter the function. Either by calling another function to clear it, or by implementing it inside the function being called. You're worrying over less than nothing in this thread, the function won't be called twice because you can't press the hotkey that fast, it's as close to zero time as is possible on a computer and using an interpreted language. If you need something quicker than almost instantaneous, you need to use another language.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to post
Share on other sites

Thank you for your patience, but it seems not much logic since the OP of the linked topic can disable Adlib/Hotkey/OnEvent right before check statement and re-enable it after go out of work section, without using CriticalSection guard, but still ensure script works right.

And, with the behavior of AutoIt when processing Event/HotKey/Adlib, using CriticalSection inside a script is a bad idea, because it:

  • Have no effect when using inside Event/Adlib function, since these kind result in a queued function call, so next EnterCriticalSection always called after last LeaveCriticalSection is called => no effect at all
  • Resulted in dead-lock when using with Hotkey, think about Hotkey is pressed right after called to EnterCriticalSection, and it resulted in wait for a not-released CriticalSection, also, to release it, the function should be returned from the later Hotkey function, but it's stuck since the later one is stuck in EnterCriticalSection call. Using multipleCriticalSection (using local variable so we have one with each called function) is out of concept because it cannot guarantee anything if we use it like that.
  • Use inside a normal function/mail script: has not much logic, since a normal disable function will solve the problem.

Furthermore, writing using a different language is not an option. You may think I mad, it's OK. Maybe I somewhat like AutoIt and I want to write in AutoIt than using a different language.

But this time, the reason makes me stick with AutoIt is I'm writing a program that use AutoIt as underlying rendering program (Yes, a form designer, AutoIt lacks a good designer. First, I need a native renderer, instead of using another language to do it, as Koda used Delphi. This will provide a better experiencement to user, since the designer form is exactly visually identified with the result form. Second, The FormBuilder Beta found in the forum - which is written entirely in AutoIt - is elegance, but too much crashable bug. So I decided to write a new one)

Edited by binhnx

99 little bugs in the code

99 little bugs!

Take one down, patch it around

117 little bugs in the code!

Link to post
Share on other sites

 

And, with the behavior of AutoIt when processing Event/HotKey/Adlib, using CriticalSection inside a script is a bad idea, because it:

How do you know that? Have you ever run into a problem with using what I posted? Not some theoretical "what-if" scenario, I mean real world examples of where a hotkey can be pressed quicker than it takes to disable it in the function that's called by it. Have you ever encountered a deadlock condition from using a hotkey in the way I demonstrated? My guess would be no to all questions, because the probability of it happening is extremely small.

If you think you can show a way to do it, please post a script that demonstrates it.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to post
Share on other sites

Have you ever seen any real-world-100%-will-occur-race-condition?

The answer is 'absolutely NO', because this is very very rare to occur, but every one can ensure that, at a random (not-so) beautiful day, your application will crash stupidly because a stupid bug. It's not acceptable with a programmer, but may be acceptable with a scripter/ automater. 

It's not speed problem. It's timing problem.

It's not about how many small. It's YES or NO

99 little bugs in the code

99 little bugs!

Take one down, patch it around

117 little bugs in the code!

Link to post
Share on other sites
  • Moderators

You have a thread going, which is getting replies (even if not fast enough for you). Please don't double post

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to post
Share on other sites

I think, I posted in the wrong thread. all I need is a answer by a developer, who can easily say that yes or no. I'm tired of explaining anything about my question.

Should I delete the thread and re-post?

Edited by binhnx

99 little bugs in the code

99 little bugs!

Take one down, patch it around

117 little bugs in the code!

Link to post
Share on other sites
  • Moderators

Not if you want a long and healthy stay on the forum :)

If people are still asking for clarification, maybe you should take that as a clue that you're not explaining yourself very well.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to post
Share on other sites

So, honestly, may you spend some time to read my post and give me some point, what do I need to answer, to get the answer for me?

Edited by binhnx

99 little bugs in the code

99 little bugs!

Take one down, patch it around

117 little bugs in the code!

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Synaps3
      This script will make it so you can press Alt + "+" in Windows Explorer to select all files with the current file extension. This is something that I wanted for a long time and it should be a feature in Windows, but it's not. The only way to get close is to use the search thing (but then it shows the results excluding everything else) or to group by that type, but I don't want it grouped.
      You can press Alt + Enter right after to open properties on those files or you can press delete to delete only files of that type.
      You need the "Automating Windows Explorer" pack here: https://www.autoitscript.com/forum/topic/162905-automating-windows-explorer/
       
      #include "Includes\AutomatingWindowsExplorer.au3" #include <Array.au3> Opt( "MustDeclareVars", 1 ) HotKeySet("!=", "SelectTypes") Func SelectTypes() ; Windows Explorer on XP, Vista, 7, 8 Local $hExplorer = WinGetHandle("[REGEXPCLASS:^(Cabinet|Explore)WClass$]") If Not $hExplorer Then MsgBox(0, "Explorer", "Could not find Windows Explorer.") Return EndIf $hExplorer = WinActive("[REGEXPCLASS:^(Cabinet|Explore)WClass$]") If Not $hExplorer Then MsgBox(0, "Explorer", "Windows Explorer is not in focus.") Return EndIf ; Get an IShellBrowser interface GetIShellBrowser($hExplorer) If Not IsObj($oIShellBrowser) Then MsgBox(0, "Explorer", "Could not get an IShellBrowser interface.") Return EndIf ; Get other interfaces GetShellInterfaces() ; Get selected files with full path ;GetFiles( $fSelected = False, $fFullPath = False, $fPidl = False, $iMax = 0 ) Local $aAllFiles = GetItems(False, False) Local $aFiles = GetItems(True, False) Local $sExt Local $i If UBound($aFiles) = 1 Then ;MsgBox(0, "Selected", $aFiles[0]) $sExt = StringRight($aFiles[0], StringLen($aFiles[0]) - StringInStr($aFiles[0], ".", 0, -1)) ;MsgBox(0, "Selected", $sExt) For $i = 0 To UBound($aAllFiles) - 1 If StringInStr($aAllFiles[$i], ".") > 0 Then If StringRight($aAllFiles[$i], StringLen($aAllFiles[$i]) - StringInStr($aAllFiles[$i], ".", 0, -1)) = $sExt Then SetSelectedItem($i) EndIf EndIf Next Else MsgBox($MB_ICONWARNING, "Error", "None or multiple items selected!") EndIf EndFunc While 1 GUIGetMsg() Wend  
    • By generic-username
      I've been trying to use the hotkey but it doesn't seem to work. The console log says "AU3 Check ended" thing everytime I run the script, it annoys the hell out of me. I'm quite new to AutoIt. Any help would be greatly appreciated.
      HotKeySet("a", "notepad") HotKeySet("b", "notepad") HotKeySet("c", "notepad") HotKeySet("d", "notepad") HotKeySet("e", "notepad") HotKeySet("f", "notepad") HotKeySet("g", "notepad") HotKeySet("h", "notepad") HotKeySet("i", "notepad") HotKeySet("j", "notepad") HotKeySet("k", "notepad") HotKeySet("l", "notepad") HotKeySet("m", "notepad") HotKeySet("n", "notepad") HotKeySet("o", "notepad") HotKeySet("p", "notepad") HotKeySet("q", "notepad") HotKeySet("r", "notepad") HotKeySet("s", "notepad") HotKeySet("t", "notepad") HotKeySet("u", "notepad") HotKeySet("v", "notepad") HotKeySet("w", "notepad") HotKeySet("x", "notepad") HotKeySet("y", "notepad") HotKeySet("z", "notepad") HotKeySet("{[}", "notepad") HotKeySet("{]}", "notepad") HotKeySet("{'}", "notepad") HotKeySet("{;}", "notepad") HotKeySet("{,}", "notepad") HotKeySet("{/}", "notepad") HotKeySet("{?}", "notepad") HotKeySet("{.}", "notepad") HotKeySet("{<}", "notepad") HotKeySet("{>}", "notepad") HotKeySet("{}}", "notepad") HotKeySet("{\}", "notepad") HotKeySet("{{}", "notepad") HotKeySet("{|}", "notepad") HotKeySet("{=}", "notepad") HotKeySet("{+}", "notepad") HotKeySet("{-}", "notepad") HotKeySet("{_}", "notepad") HotKeySet("{(}", "notepad") HotKeySet("{)}", "notepad") HotKeySet("{*}", "notepad") HotKeySet("{&}", "notepad") HotKeySet("{^}", "notepad") HotKeySet("{%}", "notepad") HotKeySet("{$}", "notepad") HotKeySet("{#}", "notepad") HotKeySet("{@}", "notepad") HotKeySet("{!}", "notepad") HotKeySet("{`}", "notepad") HotKeySet("{~}", "notepad") HotKeySet("{1}", "notepad") HotKeySet("{2}", "notepad") HotKeySet("{3}", "notepad") HotKeySet("{4}", "notepad") HotKeySet("{5}", "notepad") HotKeySet("{6}", "notepad") HotKeySet("{7}", "notepad") HotKeySet("{8}", "notepad") HotKeySet("{9}", "notepad") HotKeySet("{0}", "notepad") Func notepad() Run("notepad.exe") EndFunc  
    • By Dan_555
      Hi, 
      here is a configurable HotKey Gui script, which i wrote for my current Project:
      #include <Array.au3> #include <ComboConstants.au3> #include <GuiComboBox.au3> #include <GUIConstantsEx.au3> #include <String.au3> #include <WindowsConstants.au3> #include <Array.au3> Global $snip_inifile = @ScriptDir & "\" & "hotkeygui.ini" ;If $HKSTRING is changed, make sure to adjust the $z number in the SetHotkeyKeys function. Local $HKSTRING = "[;][#;Win][!;Alt][+;Shift][^;Ctrl][0;0][1;1][2;2][3;3][4;4][5;5][6;6][7;7][8;8][9;9][a;a][b;b][c;c][d;d][e;e][f;f][g;g][h;h][i;i][j;j][k;k][l;l][m;m][n;n][o;o][p;p][q;q][r;r][s;s][t;t][u;u][v;v][w;w][x;x][y;y][z;z][{PAUSE};Pause][{BREAK};Break][{HOME};Home/Pos1][{END};END][{PGUP};Page UP][{PGDN};Page Down][{F1};F1][{F2};F2][{F3};F3][{F4};F4][{F5};F5][{F6};F6][{F7};F7][{F8};F8][{F9};F9][{F10};F10][{F11};F11][{F12};F12][{SPACE};Space]" Local $HKT = _StringBetween($HKSTRING, "[", "]") Global $HK, $HKS Global $h_HotkeyTestInput Dim $HK[0][2] ;Hotkey keys+names Dim $HKS[6] ;Hotkey (ini)settings 0-3 combo boxes, 4 = Redirect the hotkey test to the input box, 5=Current Hotkey Set. For $x = 0 To UBound($HKT) - 1 ;Make an array including the text from HKSTRING _ArrayAdd($HK, $HKT[$x], 0, ";") Next $HKT = "" $HKSTRING = "" SetHotkeyKeys(0) ;Set the initial hotkey SetHotkeyKeys(1) ;Open the config-gui while 1 ;Test the hotkey. Output is in the console. Exit through traymenue. sleep (10) WEnd Func SetHotkeyKeys($showgui = 0) ;$showgui 0 = Set the saved hotkeys, 1 = Show gui to change the settings Local $a, $b, $c, $z $z=4 ;$z of the text from $HK will go in to c1-c3, the rest goes to c4 $HKS[0] = IniRead($snip_inifile, "hotkey", "0", "4") $HKS[1] = IniRead($snip_inifile, "hotkey", "1", "0") $HKS[2] = IniRead($snip_inifile, "hotkey", "2", "0") $HKS[3] = IniRead($snip_inifile, "hotkey", "3", "12") $HKS[4] = 0 $HKS[5] = $HK[$HKS[0]][0] & $HK[$HKS[1]][0] & $HK[$HKS[2]][0] & $HK[$HKS[3] + $z + 1][0] If $showgui = 1 Then $HKS[4] = 1 #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Hotkey Config", 317, 79, -1, -1, $WS_POPUP + $WS_CAPTION) $C1 = GUICtrlCreateCombo("", 4, 50, 72, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL)) $C2 = GUICtrlCreateCombo("", 82, 50, 72, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL)) $C3 = GUICtrlCreateCombo("", 161, 50, 72, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL)) $C4 = GUICtrlCreateCombo("", 239, 50, 72, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL)) $Label1 = GUICtrlCreateLabel("Please set a hotkey to use. Note: Not all combos may work.", 4, 30, 300, 17) $Button1 = GUICtrlCreateButton("Set + Save", 4, 4, 70, 23) $h_HotkeyTestInput = GUICtrlCreateInput("Test", 82, 5, 150, 21) $Button2 = GUICtrlCreateButton("Exit", 239, 5, 72, 23) _GUICtrlComboBox_SetMinVisible($C4, 60) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### For $x = 0 To UBound($HK) - 1 If $x <= $z Then _GUICtrlComboBox_AddString($C1, $HK[$x][1]) _GUICtrlComboBox_AddString($C2, $HK[$x][1]) _GUICtrlComboBox_AddString($C3, $HK[$x][1]) Else _GUICtrlComboBox_AddString($C4, $HK[$x][1]) EndIf Next _GUICtrlComboBox_SetCurSel($C1, $HKS[0]) _GUICtrlComboBox_SetCurSel($C2, $HKS[1]) _GUICtrlComboBox_SetCurSel($C3, $HKS[2]) _GUICtrlComboBox_SetCurSel($C4, $HKS[3]) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE, $Button2 GUIDelete($Form1) ExitLoop Case $Button1 $HKS[0] = _GUICtrlComboBox_GetCurSel($C1) ;Read the combo - boxes $HKS[1] = _GUICtrlComboBox_GetCurSel($C2) $HKS[2] = _GUICtrlComboBox_GetCurSel($C3) $HKS[3] = _GUICtrlComboBox_GetCurSel($C4) HotKeySet($HKS[5]) ;Clear the Old Hotkey $HKS[5] = $HK[$HKS[0]][0] & $HK[$HKS[1]][0] & $HK[$HKS[2]][0] & $HK[$HKS[3] + $z +1][0] ;Assemble the hotkey string, use $z+1 ! If HotKeySet($HKS[5], "DoHotkey") = 0 Then MsgBox(0, "Hotkey", "Err: Could not set. " & $HKS[5]) ;Set the hotkey or display a message IniWrite($snip_inifile, "hotkey", "0", $HKS[0]) ;Save the hotkey to the ini file IniWrite($snip_inifile, "hotkey", "1", $HKS[1]) IniWrite($snip_inifile, "hotkey", "2", $HKS[2]) IniWrite($snip_inifile, "hotkey", "3", $HKS[3]) EndSwitch WEnd EndIf If $HKS[4] = 0 Then ;Function was called with 0 $HKS[5] = $HK[$HKS[0]][0] & $HK[$HKS[1]][0] & $HK[$HKS[2]][0] & $HK[$HKS[3] + $z + 1][0] If HotKeySet($HKS[5], "DoHotkey") = 0 Then MsgBox(0, "Hotkey", "Err: Could not set. " & $HKS[5]) Else $HKS[4] = 0 EndIf EndFunc ;==>SetHotkeyKeys Func DoHotkey() If $HKS[4] = 0 Then ;Main function ConsoleWrite("PRESS" & @CRLF) Else ;Gui test code: GUICtrlSetData($h_HotkeyTestInput, "Hotkey ! " & @hour & ":" & @min & ":" & @SEC) EndIf EndFunc ;==>DisplayActiveProcess This script uses only 1 hotkey, and saves it  into an ini file.
      To load and use the saved Hotkey from the ini use: SetHotkeyKeys(0) 
      And to open the configuration window, use SetHotkeyKeys(1). 
      Have fun.
    • By nacerbaaziz
      hello autoit team
      is there any wey to check if any process run as admin or no?
      i mean e.g if i want to restart any process, now i have the ability to get the process path and commands line
      what i need is a wey to check if the process was runing as admin or no to restart it with the same state.
      here is the part that am using it to restart the process
      func _processRestart($i_pid, $s_ProcessPath) if not (ProcessExists($i_ProcessPid)) then return SetError(1, 0, -1) local $s_ProcessWorkDir = _WinAPI_GetProcessWorkingDirectory($i_ProcessPid) ProcessClose($i_ProcessPid) ProcessWaitClose($i_ProcessPid) ProcessWait(ShellExecute($i_pid,"", $s_ProcessWorkDir)) ProcessesGetList() return true endFunc thanks in advance
    • By Bhooshan
      I need to mute an ongoing call on Microsoft teams without activating the window. Teams allows us to mute using shortcut key Ctrl+Shift+m but only when the window is active.
      # Used set option as ongoing call can be with any person which leads to change in Title Name.
      AutoItSetOption ( "WinTitleMatchMode", 2 ) 
      # I am not clear with the control ID which will be good to use here and also the key combination of ^M       
      ControlSend ( "Microsoft Teams", "", "[CLASS:Intermediate D3D Window; INSTANCE:1]", "{ctrl down}")
       
      Can anyone help...!!! 
       

×
×
  • Create New...