X

Geertjan's Blog

  • October 3, 2006

Key Stroke Listener

Geertjan Wielenga
Product Manager
This is a small module, based on Sandip's Mark Occurrences contribution, that lets the IDE record your key strokes in the status bar. As soon as you've typed (in any editor) the text 'hello world', you receive a JOptionPane that tells you "You are forbidden to type 'Hello World'!"

In itself, that's not the most useful bit of functionality. But, knowing how to listen to key strokes in the IDE (or any app based on the NetBeans Platform) could be a very useful thing. As in Sandip's module, a toggle button appears in the toolbar, thanks to BooleanStateAction. When clicked, the listener kicks into action, listening to your key strokes and recording them in the status bar. As soon as 'hello world' appears in the status bar, the JOptionPane appears. One area where this might come in useful is... when you're working with annotations or editor hints, because somehow you need to know what the user is doing in order to respond by means of these features.

There's one odd thing with it, and that is that you need to refocus the IDE after switching on the key stroke listener (i.e., put something else in front of it, and then return the focus to the IDE). I don't know why that is, but it's good to know. You know it is working when you see your key strokes appearing in the status bar.

Interested? Here it is: org-netbeans-modules-keystrokelistenersample.nbm

After installing the NBM file (in NetBeans IDE 5.5 Beta 2 only), you'll have a new sample in the New Project wizard's NetBeans Plug-in Modules Sample category. It is called "Key Stroke Listener Sample".

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.