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:
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
Please sign in to leave a comment.
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.
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
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?
Please check AnActionListener:
https://upsource.jetbrains.com/idea-ce/file/idea-ce-6a856f22b82f6478cd6fbdc0f281c28d5c75b712/platform/editor-ui-api/src/com/intellij/openapi/actionSystem/ex/AnActionListener.java
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
Hi,
Please try with IdeEventQueue.addDispatcher() then.