Window looses focus

Hello

I am running OSC on a PC (win10) that also is running Cubase 10.5 using a second touchscreeen mionitor - all works fine. However, there is an issue with windows focus.

If I press a button on my OSC template on the touchscreen monitor, the relevant control is sent fine, but off course, windows has now focused on the touch OSC window and not Cubase. If I then use for example, a shortcut keyboard (qwerty keyboard), I have to manually use the mouse to refocus windows back to Cubase, then my shortcut keyboard works.

Is there a way that after each keypress on OSC, it sends a command to bring the main cubase window back to focus?

I apologise if this is a very simple question - I have googled it but can’t find an answer. I hope someone could help

Many thanks

OSC can’t do that currently. It seems possible theoretically, I’ll try to dig the idea.

Many thanks for the reply - I had previously used a piece of software to control Cubase which had options to pull windows to focus - so you could add that AFTER a key stroke, thus returning Cubase as in focus. I’m not a programmer so have no idea how to achieve something like that.

You should be proud of the software you have developed - very good indeed

Thank you. I’ve added a new function to the script widget (and the widgets’ script property): calling unfocus() will tell the OS to give the focus to the previously focused window. It will only work with the built-in client, not with external browsers.

1 Like

Maany thanks for the quick repsonse and implimentation

Hi, i would like to add the exact same fonction to my OSC project but i can’t find where i should add this line “unfocus()” … Is it in a script widget or in the script value of my already programmed widgets ? Should i just tape in “unfocus()” ?

Is it in a script widget or in the script value of my already programmed widgets ?

Either of these is fine, but it will only be executed when the widget’s value is updated. See

Ok great, thank you a lot i managed to make things working . One last question, what is the best way to implement this to the full project ? where should i past this ?

1 Like

Would also appreciate the answer to this!

You could write a small custom module that triggers the script whenever an osc message is sent

module.exports = {

    oscOutFilter:function(data){
        // Filter outgoing osc messages
        var {address, args, host, port, clientId} = data


        // send back a message to trigger the widget with "unfocus()" in its script
        receive('/script_widget_address', 1)
        

        // return data if you want the message to be and sent
        return {address, args, host, port}
    }
    
}