Keypress Listener


Hello, I am writing a little plugin in which I want to listen if the user types anything in an editor and then do something based on the keystrokes. 

I don't need to know which keys exactly are pressed just whether keys are pressed at all or not. Is there a listener that I can use in order to listen to the keystrokes done in the IDE? 


Best regards 


Comment actions Permalink

Please explain your use case in more detail. What keystrokes? single ones? or actual, "real" input? in any context? etc.

Comment actions Permalink

Hi Thanks for response. 

I want to track if any key was pressed each time a key is pressed. So say if a programmer within his project types "aaaa" I want four events each stating (at least) that a key was pressed (and preferably ) which key was pressed. I hope this clarifies

Comment actions Permalink

Do you by any chance also know how I can add functionality to the execute method without overwriting the already existing functionality. My problem is that when I can't get hold of the default 'typedActionHandler' to use it's execute method after I did what i wanted to do with the 'typedActionHandler'.

To clarify the scenario is: 
1) the programmer presses any key
2) my custom typedActionHandler gets active and calls one of my services to do stuff
3) the custom typedActionHandler calls the default typedActionHandler to proceed with the key press of the programmer 

How do i get the default typedActionHandler?

Comment actions Permalink

Found a working solution: 

in plugin.xml: 

<extensions defaultExtensionNs="com.intellij">
<typedHandler implementation="Package.MyKeyHandler"/>

in class file: 

public class MyKeyHandler extends TypedHandlerDelegate {

public Result charTyped(char c, Project project, Editor editor, PsiFile file) {
//Do stuff you wanna do here
return Result.CONTINUE;

Please sign in to leave a comment.