Issue With Autohotkey and OBS communication

CaughtInItsMaw

New Member
So, I've been having an issue with using OBS with Autohotkey. Before anything, i wanted to state nothing is being run as Admin. Running OBS as Admin breaks everything for some reason.

I purchased a mini keyboard for use as a streamdeck alternative. I have set it up so every key on the keyboard is "Ctrl+Alt+[default key]." I then used the built-in hotkey tool for OBS in order to create various hotkeys that do different things in OBS. Such as, Ctrl+Alt+Q Switches to my PC scene, Ctrl+Alt+W switches to my elgato, Ctrl+Alt+1 goes live, etc.

OBS recognizes all the buttons correctly when setting the hotkeys, and all functions work like a charm... when my computer is focused on OBS. When I'm in a game, or even just selected on my desktop, OBS does nothing, defeating the purpose of having the keyboard. What is odd, however, is if i hold a key down for a seemingly random interval (I timed it; sometimes it's two seconds, sometimes upwards of six), the keys function as intended. However, that arbitrary and inconsistent delay does not work for me. Also, the selected hotkeys work perfectly when executed with my main keyboard, no delay, exactly as I want my mini keyboard to do.

Is there anything I can do here to get everything working as intended?
 

AaronD

Active Member
What is odd, however, is if i hold a key down for a seemingly random interval (I timed it; sometimes it's two seconds, sometimes upwards of six), the keys function as intended.
That *is* odd. Normally, I'd point to you to this, in Settings -> Advanced:
1683649465813.png

But I don't think it'll help this.

Also, the selected hotkeys work perfectly when executed with my main keyboard, no delay, exactly as I want my mini keyboard to do.
That makes me think that your second keyboard is failing. If it's still new, you might try and get a refund or exchange.

Does it type okay?
 

koala

Active Member
As far as I remember, you also need to make sure, if neither your game nor OBS nor Autohotkey are focused, the thing you do have currently focused isn't running as admin as well. That's subtle - some Windows configuration dialog windows are actually running with admin privileges, even if there was no elevation prompt when you opened them.
 

CaughtInItsMaw

New Member
That makes me think that your second keyboard is failing. If it's still new, you might try and get a refund or exchange.

Does it type okay?
The second keyboard works perfectly with other apps. Simultaneously, I have Voicemod running, and any commands I put to that work perfectly. Only one input crosses over between OBS and Voicemod, and that's how i discovered the issue. Initially I thought it was only that input having issue, but ALL inputs have issue with OBS if OBS is not focused.

And yes, I've already tried all of the Settings > Advanced > Hotkey Focus Behavior options.

As far as I remember, you also need to make sure, if neither your game nor OBS nor Autohotkey are focused, the thing you do have currently focused isn't running as admin as well. That's subtle - some Windows configuration dialog windows are actually running with admin privileges, even if there was no elevation prompt when you opened them.
I've checked, and I am not seeing anything running as Admin.
 

koala

Active Member
After reading your OP again, I wonder what role Autohotkey plays. You mentioned it in the subject, but in your OP you don't mention what you do with it. You wrote you somehow set up your mini keyboard to send CTRL+ALT+key. How exactly did you set that up? Did you write a Autohotkey script and implemented the keypresses as Autohotkey macros (in this case: how do you identify a keypress being from the mini keyboard, not from your ordinary keyboard?), or did you configure the firmware of that keyboard?

If you actually do use Autohotkey to send the modified hotkeys, please post the script you use. There are subtle different definitions one can give for sending stuff.
 

CaughtInItsMaw

New Member
After reading your OP again, I wonder what role Autohotkey plays. You mentioned it in the subject, but in your OP you don't mention what you do with it. You wrote you somehow set up your mini keyboard to send CTRL+ALT+key. How exactly did you set that up? Did you write a Autohotkey script and implemented the keypresses as Autohotkey macros (in this case: how do you identify a keypress being from the mini keyboard, not from your ordinary keyboard?), or did you configure the firmware of that keyboard?

If you actually do use Autohotkey to send the modified hotkeys, please post the script you use. There are subtle different definitions one can give for sending stuff.

The script is using is using AutoHotInterception to select the keyboard (identified with HIDMacros).

#SingleInstance force
#Persistent
#include Lib\AutoHotInterception.ahk

AHI := new AutoHotInterception()
id1 := AHI.GetDeviceIdFromHandle(false, "HID\VID_5559&PID_0001&REV_0001&MI_00")
cm1 := AHI.CreateContextManager(id1)
return


#if cm1.IsActive
::aaa::JACKPOT
0::
Send, ^!0
return
F1::
Send, ^!!
return
F2::
Send, ^!@
return
F3::
Send, ^!#
return
F4::
Send, ^!$
return
F5::
Send, ^!?
return
F6::
Send, ^!^
return
`::
Send, ^!`
return
1::
Send, ^!1
return
2::
Send, ^!2
return
3::
Send, ^!3
return
4::
Send, ^!4
return
5::
Send, ^!5
return
6::
Send, ^!6
return
Tab::
Send, ^!u
return
q::
Send, ^!q
return
w::
Send, ^!w
return
e::
Send, ^!e
return
r::
Send, ^!r
return
t::
Send, ^!t
return
y::
Send, ^!y
return
\::
Send, ^!\
return
CapsLock::
Send, ^!k
return
a::
Send, ^!a
return
s::
Send, ^!s
return
d::
Send, ^!d
return
f::
Send, ^!f
return
g::
Send, ^!g
return
h::
Send, ^!h
return
j::
Send, ^!j
return
7::
Send, ^!,
return
z::
Send, ^!z
return
x::
Send, ^!x
return
c::
Send, ^!c
return
v::
Send, ^!v
return
b::
Send, ^!b
return
Up::
Send, ^!n
return
m::
Send, ^!m
return
8::
Send, ^!8
return
9::
Send, ^9
return
-::
Send, ^!_
return
Space::
Send, ^!"
return
Left::
Send, ^!<
return
Down::
Send, ^!*
return
Right::
Send, ^!>
return
#if
^Esc::exitApp

It should also note that some of the physical keys have been bound via the included software to register as different keys (Escape key = 0, Windows = 9, Alt = _ for instance, so i can use those keys for macros when normally i wouldn't be able to).
 
Last edited:

koala

Active Member
That's quite a sophistic setup. An interesting problem to solve, however this can probably only be investigated on your system. I don't see any obvious issue - it could and should work.

About what @Suslik V wrote: You can control the timing of generated keys with SetKeyDelay. Also try to experiment with different send modes (Send/SendRaw/SendInput/SendPlay/SendEvent or to set a default with SendMode <mode>).

Try to identify the location of the issue. Does it only happen with OBS, or with every other app as well? This makes it an OBS-related issue or a general Autohotkey script issue. I usually use Notepad or some text editor as testing target app to see if generated keys are received in general. Next question to investigate: does it only happen if used with modifier keys (ctrl+alt) or with ordinary unmodified keys (A, B, C, ...) as well?
Next is to see if this #if cm1.IsActive with AutoHotInterception is really working and your hotkey section in your script is really active.

I wrote a crude logging function for own use that writes messages to a console window. May be it can help you see if the Autohotkey part of your setup is working properly. You can put some logit("debug message") lines into your hotkey definitions to see if they are actually executed.

Code:
; open console window for logging. true or false.
global LOGGING := true

[...]

logit("this is a test logging message")
[...]

; ----------------------------------------------------------------------------
; write something to the console
; open console if not yet open
logit(msg) {
    static console := ""
    global LOGGING

    if (not LOGGING) {
        if (console) {
            console.close()
            DllCall("FreeConsole")
            console := ""
        }
        return
    }

    FormatTime, ts, a_now, yyyy-MM-dd HH:mm:ss

    if (not console) {
        DllCall("AllocConsole")
        console := FileOpen("*", "w")
        console.WriteLine("")
        console.WriteLine(ts " ----- " A_ScriptName " start -----")
    }
    console.WriteLine(ts " " msg)
    console.Read(0)
}
 

CaughtInItsMaw

New Member
Try to identify the location of the issue. Does it only happen with OBS, or with every other app as well? This makes it an OBS-related issue or a general Autohotkey script issue.

Like I said, I am running Voicemod as well, and it works perfectly with the keyboard, regardless of what program is in the forefront. It even works perfectly when OBS is focused and all the macros are functioning there.

@Suslik V, I can try that.
 
Top