How to register a typedHandler dynamically?

Answered

Hi,

i want to record inputs of the user, I can currently record actions, but i want to record keypresses too. The keypresses itself should still react normally.

i want basically to do this:

https://intellij-support.jetbrains.com/hc/en-us/community/posts/206756295-TypedActionHandler-with-default-typing-behavior

but register the handler dynamically as the user doesnt want to record everything all the time -> an action starts the recording, by registering the handler.

How can i do this?

Also important is that there then needs to be a way to "turn" the typedActionHandler off too

 

 

0
6 comments

Hi,

There is no supported way of registering/unregistering extensions at runtime, so I suggest creating some service holding a flag that will be enabled/disabled by your action and checked in your handler.

1

Thanks for your answer, yes that works totally fine, i thought its more elegant to register the extensions when they are needed but no harm in using a flag

0

Another question Karol Lewandowski:

If i use the solution from the link, then it will NOT grab every pressed key because the moment a context menue opens, this keypress is not registered anymore, even if the char still appears in the file.

Am i using the wrong listener?

Is there a key handler which registers keypresses "inside" menues, but outside the editor?

0

hi, sorry for my late answer. I played around the AnActionListener and its really close to what i want to do.

I still have the problem that keypresses not done in the editor are not recorded.

for example:

* when i open the tool menu "Gradle" in intellij via shortcut

* and then enter "buil" via keyboard

* then enter

* "buildPlugin" is executed. 

What what gets recorded? 

* "Open Gradle Toolwindow"

* "buildPlugin"

I would still like to grab the "Enter" and the "buil" keypresses

0

Hi,

Please try with IdeEventQueue.addDispatcher() then.

0

Please sign in to leave a comment.