Sign in to follow this  
Followers 0
was2

Send keys once

4 posts in this topic

#1 ·  Posted (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 by was2

Share this post


Link to post
Share on other sites



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:

#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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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:

#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!

Share this post


Link to post
Share on other sites

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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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