evilC / AutoHotInterception

An AutoHotkey wrapper for the Interception driver
MIT License
739 stars 65 forks source link

destroy ContextManager #73

Closed serzh82saratov closed 1 year ago

serzh82saratov commented 3 years ago

Hey! Is it possible to cancel the context? How can I call interception_destroy_context.

serzh82saratov commented 3 years ago

If I do this for everyone try AHI.CreateContextManager (0) Or so for one AHI.Instance.SetContextCallback (4, {}) Can this affect stability?

evilC commented 3 years ago

If it doesn't crash when you do it, I guess not, but TBH I would be kind of surprised if it worked. Certainly, once you add a ContextManager, just setting the function object for that device to nothing ie AHI.Instance.SetContextCallback (4, {}) will not stop the code from thinking that there is a context manager for that device, and it will attempt to fire it. However, a subscription always takes priority over context. If there is a subscription present for a given binding, then it will not attempt to fire the context manager for that input

serzh82saratov commented 3 years ago

If there is a subscription present for a given binding,

My context is used for all keys. And my main need is just to turn off any AHI activity, for a while.

try AHI.CreateContextManager (0)

This works, disables all context. But of course I am confused by the error in this case. More over, only one call to CreateContextManager with any index includes the context for all previously registered (I have these are the first 10). I tried it 1000 times and I didn't notice any problems.

loop 1000
{
    try AHI.CreateContextManager(0)
    ToolTip % A_Index
    AHI.CreateContextManager(1) 
}
evilC commented 3 years ago

There's a specific command for turning AHI on and off - SetState()

serzh82saratov commented 3 years ago

I haven't seen it before, is it in the new version? I downloaded v0.5.3, tried it AHI.SetState(0) and my script freezes.

evilC commented 1 year ago

I see no problem with the following code:

AHI := new AutoHotInterception()
enabled := true
keyboardId := AHI.GetKeyboardId(0x04F2, 0x0112)
cm1 := AHI.CreateContextManager(keyboardId)
return

x::
    enabled := !enabled
    AHI.SetState(enabled)
    return

#If cm1.IsActive
1::
    ToolTip("KEY DOWN EVENT @ " A_TickCount)
    return

1 up::
    ToolTip("KEY UP EVENT @ " A_TickCount)
    return
#If

Hit 1 on the keyboard - tooltip shows. Hit x - tooltip stops showing when you hit 1 Hit x again - tooltip starts showing when you hit 1