Disablying keyboard events in a JFrame.

Hello,
How is it possible to disable keyboard events for a specific JFrame and then (after a while) enable events again ?
thank you,
Rami

Look at this program, events are send but you can't see the data in the fields.
import java.awt.*;
import java.awt.event.*;
public class Nok extends Frame
public Nok()
     super();
     setBounds(6,6,400,300);     
     addWindowListener(new WindowAdapter()
    {     public void windowClosing(WindowEvent ev)
               dispose();     
               System.exit(0);
     setLayout(new GridLayout(4,0));     
     add(new TextField("this is a text field"));
     add(new TextArea("this is a text area"));
     add(new Button("this is a button"));
     setVisible(true);
     Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener()
     {     public void eventDispatched(AWTEvent e)
               System.out.println(""+e);
               ((KeyEvent)e).consume();
     }   ,AWTEvent.KEY_EVENT_MASK);
public static void main (String[] args)
     new Nok();  
Noah
import java.awt.*;
import java.awt.event.*;
public class Nok extends Frame
public Nok()
     super();
     setBounds(6,6,400,300);     
     addWindowListener(new WindowAdapter()
{     public void windowClosing(WindowEvent ev)
               dispose();
               System.exit(0);
     setLayout(new GridLayout(4,0));     
     add(new TextField("this is a text field"));
     add(new TextArea("this is a text area"));
     add(new Button("this is a button"));
     setVisible(true);
     Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener()
     {     public void eventDispatched(AWTEvent e)
               System.out.println(""+e);
               ((KeyEvent)e).consume();
     } ,AWTEvent.KEY_EVENT_MASK);
public static void main (String[] args)
     new Nok();

Similar Messages

  • Disable datagrid keyboard events

    Is it possible to disable keyboard events or prevent the datagrid from switching selected rows?  In my app, I allow the user to select a datagrid row, but when they do I make a request to get data. While I am waiting for the data to return I want to prevent the user from using the keyboard arrow keys to select another row.
    I have tried setting selectable to false and setting focusEnabled to false, but neither one works.  Anyone know of another alternative?
    TIA

    Block the keyDown event or override  moveSelectionVertically

  • In Flashplayer, I can crossover mouse and keyboard events. In IrfanView I cannot. Can this be fixed?

    My client uses IrfanView to play SWF files. Unfortunately, he does not use Flashplayer. In Flashplayer, I can crossover mouse and keyboard events with no problem. In IrfanView, the second I click a button, the keyboard events are disabled. Is there a fix?

    Hi Ned. I may have posted this issue a bit early, but this problem is also happening in Flashplayer 10. It's not exclusive to IrfanView.
    Here is something that I encountered during my testing, when I jump to scene 6 using the menu button, I have a play button to jump from one frame to the next frame that stops -- the keyboard events start working. But if all I am doing is jumping scene to scene with the mouse button, the keyboard events are disabled.
    I feel as if the keyboard events only work if I am playing frames in the scene. And if all I am doing is jumping scene to scene using the buttons, the keys will disable.
    I set up the mouse buttons inside a movieclip that all the scenes share. The mouse actionscript is in the movieclip. On the main timeline of each scene is an actionscript for the keyboard events, even though I had to change each function name.
    I feel the actionscript is setup pretty simple. I just wish clicking the buttons would not disable the keyboard events. This may sound redundant, but the keyboard events do the same thing if you use the mouse buttons. It's just preference for the client even though he will need to understand that using the mouse buttons override the keyboard events. He doesn't really lose functionality.
    Keyboard actionscripting below:
    import flash.events.KeyboardEvent;
    stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyEvent);
    function onKeyEvent(e:KeyboardEvent):void {
    var character:String=String.fromCharCode(e.charCode);
    if (e.keyCode==72) {
      gotoAndStop(1,"master");
    if (e.charCode==49) {
      gotoAndPlay(1,"Distributor");
    if (e.charCode==50) {
      gotoAndPlay(1,"Mirka");
    if (e.charCode==51) {
      gotoAndPlay(1,"Farm");
    if (e.charCode==52) {
      gotoAndPlay(1,"Check2");
    if (e.charCode==53) {
      gotoAndPlay(1,"Check3");
    if (e.charCode==54) {
      gotoAndPlay(1,"Scene2");
    if (e.charCode==55) {
      gotoAndPlay(1,"Scene1");

  • Disabling mouse events

    hi,
    I am having objects on a JFrame that respond to mouse events. I would like to know how I can disable these events. I use the addMouseListener to register a mouse event on something. Is there a way to remove or to deregister mouse events.
    I basically have a game of tiles on a JFrame and I am going to have the human player play against the computer. I want to be able to have turns; computer and human player turn.

    removeMouseListener()

  • Handling keyboard events in applets?! Possible?!

    Hello,
    I wrote a little game that uses keyboard handling events. It is an applet that can also standalone as an application. When i run the program as a standalone application, it handles keyboard inputs fine. ie...i can press the left and right arrow keys and something happens.
    But when i run my program as an applet in a web browser, the applet starts up correctly but does not handle any keyboard events. It only handles mouse events. For instance, if i press the up and down arrow keys, the browser window scrolls up and down!!! And the up and down arrow keys have a specific purpose in my applet.
    QUESTION: how do i get my applet to accept keyboard inputs such as UP,DOWN, LEFT, RIGHT?

    Hmm something went wrong w/ my post so i hope this doesnt show up twice.
    Hey thanks a lot for helping me out. The applet/application is large so here is the main() method and the keyboard event handling class code. My question is how come the keyboard events get properly handled when i run it as a standalone application, but keyboard events go to the browser when i run it as an applet? I would post my entire code but it's over 1000 lines and spread out over 8 files. hehehe.
    Here is main():
      public static void main(String[] args)
          MyProgram applet = new MyProgram();
          applet.isStandalone = true;
          JFrame frame = new JFrame();
          frame.setTitle("Physics: Kinematics");
          frame.getContentPane().add(applet, BorderLayout.CENTER);
          applet.init();                        // initialize the applet inside frame
          applet.addKeyListener(kbHandler);     // kbHandler is a keyboard handling object
          applet.start();
          frame.setSize(APPLETWIDTH,APPLETHEIGHT);
          Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
          frame.setLocation((d.width - frame.getSize().width) / 2, (d.height - frame.getSize().height) / 2);
          frame.setVisible(true);
          // private inner class to terminate the Application when frame closes
          frame.addWindowListener(
            new WindowAdapter()
                public void windowClosing(WindowEvent e)
                    System.exit(0);
          frame.show();
       }"kbHandler" is the keyboard event handling object. It gets initialized in the applet.init() method.
    kbHandler = new BMkeyboardHandler();And here is the keyboard event handling code:
    // ===== keyboard event handler ===========
       private class BMkeyboardHandler implements KeyListener
            public void keyPressed(KeyEvent e)
                pushedKey = e.getKeyCode();
                // General administrative key actions
                if(pushedKey == KE.VK_H)
                    actionArea.toggleHelpMenu();
                    actionArea.repaint();
                else if(pushedKey == KE.VK_C)
                    actionArea.toggleCtrlMenu();
                    actionArea.repaint();
         }So there it is. Again, the program handles events fine as a standalone application. But running it as an applet in a browser (and even the appletviewer) doesnt let me handle keystrokes.

  • How can we disable keyboard shortcuts on webpages?

    I am using the add-on firemacs, which allows us to edit text with emacs key-bindings.
    The problem is: some key-bindings (set by firemacs) are overwritten at several webpages (e.g. Evernote and StackExchange).
    For example, Ctrl-b moves normally the text cursor to the previous character in a textarea. But in the textarea at any site of StackExchange, Ctrl-b creates `**strong text**`.
    Is it possible to disable keyboard shortcuts without disabling shortcuts for firemacs?
    The trivial solution is to disable JavaScript. But I want to know a possibility of other solutions.

    StackExchange links to a bunch of other sites, so I looked at the superuser.com site. The specific script that creates the interactive features of the editor is http://cdn.sstatic.net/Js/wmd.en.js. It's minified so I can't figure out the call needed to remove the keypress event listener. (Actually, I'm not sure I could figure it out even with the full source, as I don't use jQuery.) Maybe it's a question for StackOverflow?

  • Keyboard events going to InDesign and not on textbox

    Hi,
    I have ported a project from InDesign CS2 to InDesgn CS3 on Mac. I have dialogs in rsrc file (not converted to nib file) which I am also using on XCode.
    Now the problem which I am facing is that when typing in a textbox then keyboard events are going to InDesign and only those events which are not handled by InDesign is received by my textbox.
    Has anyone experienced the same problem before?
    Any help will be appreciated.
    Regards,
    Rahul Rastogi

    Start Firefox in [[Safe Mode]] to check if one of your add-ons is causing your problem (switch to the DEFAULT theme: Tools > Add-ons > Themes).<br />
    See [[Troubleshooting extensions and themes]] and [[Troubleshooting plugins]]<br />
    <br />
    If it does work in Safe-mode then disable all your extensions and then try to find which is causing it by enabling one at a time until the problem reappears.<br />
    You can use "Disable all add-ons" on the [[Safe mode]] start window to disable all extensions.<br />
    You have to close and restart Firefox after each change via "File > Exit" (Mac: "Firefox > Quit"; Linux: "File > Quit")

  • Losing Keyboard Events

    Hello Forum,
    I have a JFrame that listens for keyboards events which works find. However when I put up a glass pane the keyboard events stop. I'm not setting up any listeners on the glass pane. I know this is vage...was just hoping for any ideas on why this would be happening.
    Thanks for any input.

    the key listener will only work if it has focus. When you put up the glass pane you are taking focus from your fame and putting it on the glass, which doesn't listen so you loose the events.
    So, either add a listener to the glass pane and forward events to the frame, or change focus back to the frame after you put up the glass..

  • Mouse & Keyboard events

    Hi all,
    I�m creating an applet and this applet needs to use both keyboard and mouse events�. My problem is that when I try to enable mouse events, such as mouse click, using either this.enableEvents(AWTEvent.MOUSE_EVENT_MASK) in init() method, or using mouse listener:
    public class ThreeDSimApplet extends Applet implements Runnable, MouseListener
    and defining the required methods:
    public void mouseClicked(MouseEvent event) {
         if (event.getButton()==MouseEvent.BUTTON1) {
         mouseX=event.getX();
    mouseY=event.getY();
    System.out.println(mouseX+" ," + mouseY);
    public void mousePressed(MouseEvent event) {
    public void mouseReleased(MouseEvent event) {
    public void mouseEntered(MouseEvent event) {
    public void mouseExited(MouseEvent event) {
    the keyboard events become disabled and my keyboard doesn�t works anymore�. Exist a way to use both events in my applet?
    Bye and thanks

    Hi
    This doesn't answer your question exactly, but I suggest implementing
    a MouseAdapter instead of a MouseListener.
    That way you won't have to implement all the unused methods
    (eg mouseEntered, mouseExited etc.); just the one(s) you need
    See http://java.sun.com/docs/books/tutorial/uiswing/events/generalrules.html#eventAdapters
    Good luck for getting an answer to you question!
    lutha

  • Yoga 2 Pro: auto disabling keyboard in laptop mode bug

    Hello.
    I have a problem with my Yoga: very often (even if notebook placed on table) in laptop mode its disabling keyboard and touchpad on several seconds and then enabling it again. This enable/disble (flap) occurs time to time, most often after computer power on.
    In this case work with mail or surfing web in laptop is not possible.
    Someone have a hint how to repair it or how to enable keyboard manually permanently? Laptop is still on warranty, not broken, didn’t fall, win 8.1.
    If need i can record some video on mobile phone with keyboard on/off.

    Hi. Here it is. I tried to record the off/on process of this problem. On the seond part i typing in notepad and you can see interuption of letters. 
    https://yadi.sk/i/3GBZepRabSEpf
    Problem is still not solved

  • Can  DISABLE preProcess Event Handler add to the Orchestration parameters?

    I have a DISABLE pre-process event handler defined on the User object. I need to set the current date on a USR UDF attribute whenever the user is disabled or enabled or created. The CREATE handler works and the date value shows up on the user profile. However, when I try to set this attribute on the pre-process DISABLE or ENABLE event handlers, the new date does not show up. Here is the code I am using in my DISABLE/ENABLE event handler:
    Date currentTime = new Date(System.currentTimeMillis());
    orchestration.addParameter(USER_STATUS_DATETIME_ATTR_NAME, currentTime);
    Where the orchestration object is from the execute() parameter list.
    Any ideas as to why this is not working? Is adding to the orchestration not allowed for DISABLE or ENABLE event handlers? I know my handler is getting calls as I am logging the orchestration.getOperation() value.
    Thanks for any suggestions.
    -Dave
    Edited by: user552098 on Nov 12, 2012 1:56 PM

    When you update the field, make sure you are using the field label name, and not the UDF value.
    -Kevin

  • How can I disable the "Events" how can I disable "Faces"

    buona sera
    how can I disable the "Events"
    how can I disable "Faces"
    grazie

    You can not
    Events are one of many views or your photos in your library - as are faces
    YOu can simply ignore both but you can disable them
    LN

  • Flex 4 does not dispatch keyboard events for ENTER key.

    Hello everyone. I think I have a strange problem with Flex 4 Beta (4.0.0.8909). My application has had event listener for keyUp event for a month now and suddenly (two days ago) I've noticed that keyUp event is not dispatched for ENTER (ALT also) key. Anyone know why? By the way, I've tried this with keyDown event, also 4.0.0.8847 version of SDK - still the same: no keyboard events for ENTER (and ALT) key.
    Here is the sample application that has got this issue:
    <s:Application
       xmlns:fx="http://ns.adobe.com/mxml/2009"
       xmlns:s="library://ns.adobe.com/flex/spark"
       xmlns:mx="library://ns.adobe.com/flex/halo"
       minWidth="640" minHeight="480"
       keyUp="application1_keyUpHandler (event)">
       <fx:Script>
          <![CDATA[
             import mx.controls.Alert;
             protected function application1_keyUpHandler (event: KeyboardEvent):void
                Alert.show ("Key up: " + event.keyCode);
          ]]>
       </fx:Script>
       <s:layout>
          <s:BasicLayout/>
       </s:layout>
       <s:TextArea verticalCenter="0" horizontalCenter="0" width="200"/>
    </s:Application>
    If you run this application and try typing anything in a TextArea you will get alerts with key codes. However, if you press ENTER (or ALT), you will get no alert.
    I'm pretty sure the code above is right so that means there is a bug in latest nightly builds of SDK (i would swhitch to an older build if i knew which one does not have this bug).
    Any ideas?

    Flex harUI wrote:
    That's true, but in this case, I think the text editing code is eating ENTER key in order to prevent parents from seeing it and acting on it (like a submit button).  We'll see if we can find a way around that.
    You can get the ENTER key now by listening in capture phase.
    Alex Harui
    Flex SDK Developer
    Adobe Systems Inc.
    Blog: http://blogs.adobe.com/aharui
    The enter key isn't being disposed of by textedit, the attached example code works without error if you a- remove the alert box and b-set the focus to your text area on initialisation. I agree that pressing the enter key then calling a dialog box will result in the enter key being "gobbled up" as  the enter key is overridden by the dialog box code.
    I think the first suggestion should be to anyone don't use dialogboxes for testing code. If for some reason debugging isn't desirable instead of a trace statement a simple label  can be used as a 'fake' trace.
    David
    Message was edited by: David_F57: I worded this wrong, imho there is no need for a work around, the textarea component works as it should. When intercepting 'system' keycodes there is a need to consider the effect of the intercept and code appropriately to that end.

  • Keyboard Event Listener doesn't work in Browser

    Is there a reason why a keyboard event listener would not work if the flash is embedded in an HTML? The rest of my game is running fine in the background, but I can't launch the movieClip "nextCar." My code is below, if that makes any difference...
    function goNow (event:KeyboardEvent): void {
        thisOtherKey = event.keyCode;
        if (thisOtherKey == 32) {
            nextCar.gotoAndPlay(2);
            parkingQue.play();
            tries++;
    stage.addEventListener(KeyboardEvent.KEY_DOWN, goNow);

    This may be a silly question, but have you tryed clicking on your swf after it opens up in the browser, and then trying the keyboard controls?
    I don't know of any issues that cause event listeners to workwhen debugging, but not in a browser.  So, I'm thinking maybe your just not focused on the swf.

  • Can we catch keyboard event triggered by an inputfiled?

    Hi all,
    I have a question here:
    When we are doing the web dynpro abap development, if I want to catch the keyboard triggered by an
    input help and handle it, how can I achieve this?
    e.g.   I have an inputfield on the UI,  if user click "F10" on the keyboard, can I catch this kind of event?
    Thanks and Regards,
    Aaron

    Hi Thomas,
    Yes, I'm trying to acomplish an input help for an inputfield.But, the free programmed value or OVS or dictionary search help can fullfill my needs.Here is the situation:
    I have a inputfield on the UI, and next to that , I have another textview, which should be changed according inputfield. e.g.  the inputfield is a user name, and next to that , is the user id. but we only want the input help for user name. so when user select one row iof the search result table, I want that two fields both filled.
    1. the OVS can't meet my need because I can't change the layout of the search result table, I need a table with a tree in it.
    2. free programmed value help can only send back the value of the inputfield. although maybe I can get the user_id's context attribute name and by hardcoding and send back also the user id. but I don't like hardcoding.
    So, I'm wondering whether I could catch the keyboard event. and handle the F4 help all by myself.
    Do you have some suggestion on this?
    Thanks and Regards,
    Aaron

Maybe you are looking for

  • How to stop clearing open items with manual payment block.

    Dear, Even though we have set "manual payment block" on payment block indicator in OB27, I can process to clear open items manually in F-44 though. Actually user wants to NOT allow to clear once payment block's set in an open items. SAP documentation

  • Possible to update Flash without admin rights AND without internal server?

    We have numerous laptops and tablets that are rarely, if ever, connected to our internal network.  All of our users are standard users; our users are not allowed to be administrator users. Nonetheless, we'd like Flash Player to automatically update i

  • Lego indiana jones

    Hello everybody, some days ago I bought a cable from the Apple Store in order to link my iMac to my Samsung LCD tv and duplicate the screen. Everything runs, but I have two problems: I can't use the game Lego Indiana Jones 2 because, when the iMac is

  • How to launch a Java WebStart application with older JREs when Java 7u25 is on the client?

    How can I launch older versions of my Java WebStart application, that are built and run with Java 7u21 or earlier, even if Java 7u25 is installed locally on the client? Application launch and behaviour must be reliable and consistent. Background: As

  • 10.4.7 update screws up image file associations

    Since installing the 10.4.7 update, all my image files now open in Preview as the default application, regardless of Type or Creator. I know that the file association of an individual can be changed via Get Info, however, I have 11,000+ image files i