SniperVishal
asked on
How to disable keyboard keys (printscrn, ctrl+c)?
I would like to know how can i disable keyboard keys -- printscrn, ctrl+c in a java application? Is there any class or way to do it?
ASKER
I got a form (GUI) with a jTable in it and want to disable the ctrl+c and print scrn keys so that no one can copy the contents of the jTable and screen also cannot be captured...
If its a console application, I don't think you can do anything about it. Ctrl-C on the JVM window will probably terminate it - the best you can do is write a shut-down hook and catch it to do some final clean-up.
You can do this ONLY when yor GUI is ion focus. If a user was to bring another window into focus, but your GUI was still visible, then you wont be able to disable this functionality.
colr__
colr__
>> print scrn keys
Not sure if you can do that because that key is likely to be caught by the OS directly, not the Java app.
Not sure if you can do that because that key is likely to be caught by the OS directly, not the Java app.
ASKER
the user should not be able to copy the values of the jTable. Its a form using swing.
ASKER
the ctrl+c ? how can i do it then? where should the key listener code be placed?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I think you need to overide the key mapping/binding for the control to disable the default functionality.
for e.g.,
table.getKeymap().addActio nForKeyStr oke(KeyStr oke.getKey Stroke(67, 128), new DefaultEditorKit.CopyActio n());
table.getKeymap().addActio
I am sorry, it should be inputMap instead of keyMap
>> where should the key listener code be placed
Perhaps you should add it to the JTable and the panel/ frame which contains it. The same listener can be used, which ignores the event.
Perhaps you should add it to the JTable and the panel/ frame which contains it. The same listener can be used, which ignores the event.
I don't think, the key lestener will work because if the key is already mapped to some action, the listener is not going to consume the action. So it is better to override the mapping.
Yes, for overriding default functionality, that might be required.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
For the jTable i disabled the cell selection and the user cannot copy the values of the cells.
For the print scrn is there any way?
For the print scrn is there any way?
I don't think, you can consume that but you can try it in the key press event. On key press, you ma greyout the frame's glasspane or minimze and then maximize. This may work if the system event gets fired on key release.
>>For the jTable i disabled the cell selection
Just curious, how did u do this?
Just curious, how did u do this?
ASKER
jTableVishal.setRowSelecti onAllowed( false);
jTableVishal.setCellSelect ionEnabled (false);
jTableVishal.setCellSelect
You could add a key listener which takes no action when those keys are pressed? But that would only work within your own application. If your looking to disbale these keys system wide, then Java isnt your tool.
colr__