Search code examples
autohotkeyobsobs-studio

Send function key stroke from AutoHotkey to OBS Studio


I am trying to send a keystroke to OBS Studio using AutoHotkey.

The code I am using is

DetectHiddenWindows, On
hWnd := WinExist("ahk_exe obs64.exe")
ControlSend,, {F5}, ahk_id %hWnd%

The function I want to trigger is "start recording"

setting in OBS

Nothing is delivered. There is a rumour that the latest OBS does not allow for ControlSend. Is that true? How do I circumvent that?


Solution

  • Use SetKeyDelay (or separate up & down events with delay in between) to make the key be held down for a bit longer.

    ;hold down for 50ms
    SetKeyDelay, -1, 50
    ControlSend, , {F5}, ahk_exe obs64.exe
    

    Also, assuming you don't need the hwnd for something else, there's no need to get it.
    And it should work just fine as well without detecting hidden windows.