was2 Posted July 8, 2013 Share Posted July 8, 2013 (edited) Hey everyone. I'm working on a simple scene switcher for OBS (Open Broadcaster Software) for my stream. In general it works, but in my opinion it works too much. Here's my Code: #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Scene Switcher ", 238, 69, 452, 309) $Label1 = GUICtrlCreateLabel("BF3, SS3, RE6, ", 8, 40, 85, 17) $Active = GUICtrlCreateCheckbox("Active", 184, 40, 49, 17) $Label2 = GUICtrlCreateLabel("Scene 1=F10, 2=F11, 3=F12", 8, 8, 229, 18) GUICtrlSetFont(-1, 10, 400, 0, "OCR A Std") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch If GUICtrlRead($Active) = 1 Then If ProcessExists("bf3.exe") Or ProcessExists("BH6.exe") Or ProcessExists("Sam3.exe") Or ProcessExists("BLR.exe") Then Send("{F10 DOWN}") Sleep(100) Send("{F10 UP}") Else Send ("{F11 DOWN}") Sleep(100) Send("{F11 UP}") EndIf EndIf WEnd F10 and F11 are hotkeys for my 2 main scenes. Now when none of these processes exist it keeps spamming f11, is there a way to prevent it from spamming it? It is supposed to send it once, but google can't give me an answer on that. Thanks for reading, I hope you can help me. PS: Can i just ad a super long sleep after SEND F11 UP? Or would that block the whole script from working? Edited July 8, 2013 by was2 Link to comment Share on other sites More sharing options...
Moderators Solution Melba23 Posted July 8, 2013 Moderators Solution Share Posted July 8, 2013 was2,Add a flag to tell you what state you are in and only fire the action if it is set to the other state - you set the correct state after having actioned the key:expandcollapse popup#include <GUIConstantsEx.au3> Global $fFlag = False ; Clear flag as nothing is running $Form1 = GUICreate("Scene Switcher ", 238, 69, 452, 309) $Label1 = GUICtrlCreateLabel("BF3, SS3, RE6, ", 8, 40, 85, 17) $Active = GUICtrlCreateCheckbox("Active", 184, 40, 49, 17) $Label2 = GUICtrlCreateLabel("Scene 1=F10, 2=F11, 3=F12", 8, 8, 229, 18) GUICtrlSetFont(-1, 10, 400, 0, "OCR A Std") GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch If GUICtrlRead($Active) = 1 Then If ProcessExists("bf3.exe") Or ProcessExists("BH6.exe") Or ProcessExists("Sam3.exe") Or ProcessExists("BLR.exe") Then ; Have we reacted to this already If $fFlag = False Then Send("{F10 DOWN}") Sleep(100) Send("{F10 UP}") $fFlag = True ; Because now something is running EndIf Else ; Was something running before? If $fFlag = True Then Send("{F11 DOWN}") Sleep(100) Send("{F11 UP}") $fFlag = False ; Well, nothing is running now EndIf EndIf EndIf WEndObviously I have not tested the scropt as I do not have access to those processes, but the principle is sound - it is how you avoid flicker on controls which depend on the state of other controls. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
was2 Posted July 8, 2013 Author Share Posted July 8, 2013 was2, Add a flag to tell you what state you are in and only fire the action if it is set to the other state - you set the correct state after having actioned the key: expandcollapse popup#include <GUIConstantsEx.au3> Global $fFlag = False ; Clear flag as nothing is running $Form1 = GUICreate("Scene Switcher ", 238, 69, 452, 309) $Label1 = GUICtrlCreateLabel("BF3, SS3, RE6, ", 8, 40, 85, 17) $Active = GUICtrlCreateCheckbox("Active", 184, 40, 49, 17) $Label2 = GUICtrlCreateLabel("Scene 1=F10, 2=F11, 3=F12", 8, 8, 229, 18) GUICtrlSetFont(-1, 10, 400, 0, "OCR A Std") GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch If GUICtrlRead($Active) = 1 Then If ProcessExists("bf3.exe") Or ProcessExists("BH6.exe") Or ProcessExists("Sam3.exe") Or ProcessExists("BLR.exe") Then ; Have we reacted to this already If $fFlag = False Then Send("{F10 DOWN}") Sleep(100) Send("{F10 UP}") $fFlag = True ; Because now something is running EndIf Else ; Was something running before? If $fFlag = True Then Send("{F11 DOWN}") Sleep(100) Send("{F11 UP}") $fFlag = False ; Well, nothing is running now EndIf EndIf EndIf WEnd Obviously I have not tested the scropt as I do not have access to those processes, but the principle is sound - it is how you avoid flicker on controls which depend on the state of other controls. M23 Thank you very much! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 8, 2013 Moderators Share Posted July 8, 2013 was2,My pleasure. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now