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

Similar Messages

  • SWT_AWT mouse/keyboard event trouble

    Hello everyone,
    I have created an ActiveX Component with Visual C++ that uses a WEmbeddedFrame to contain a Swing based GUI. I have copied the code from the SWT_AWT class in the SWT toolkit and it worked fine up to JDK 1.5.0_03.
    Starting with JDK 1.5.0_04 the Swing GUI does no longer receive Mouse/keyboard events.
    I have read through all available material concerning this problem and I have tried the two possible solutions that these documents suggest:
    - called addNotify() on the embedded frame
    - inserted a heavyweight container (java.awt.Panel) between Embedded Frame and the Swing GUI
    However, no luck. The GUI displays fine but does not respond to user actions.
    Does anybody have an idea what might have changed from 1.5.0_03 to 1.5.0_04, that could help me solve this puzzle?
    Thank you very much in advance,
    Helmut

    SWT works up to 1 tree and two text components only. If you have more than that, you windows will get tainted. Basically it's useless to wirte any useful programs for Windows. You never get comaptible latest look from it both mac and windows. Don't waste time for learning it. You better spend time for learning other things. If AWT/Swing is not good enough, learn native languages such as Visual C++/Basic! I have to say SWT wasn't meant to give us better programming platform!

  • Mouse/keyboard events lost during sound events

    I have a new MacbookPro (October 2011, MacBookPro8,2) with 4Gb RAM running latest 10.6.8, and I am extremely frustrated by periodic loss of mouse events (movement freezes, then jumps) and keyboard events (loss of keystrokes) whenever a sound alert is made. Am I the only person experiencing this?

    I should also add a related behavior, repeated keypresses. I do a lot of work on connected unix/linux machines using terminal. Sometimes I will be navigating directories and hit <tab> for command completion, and unexpectedly get the screen scrolling as if I had typed it 100 times!

  • Recieving Mouse/Keyboard events in independent object?

    I'm currently writing a class Map, which is supposed to, surprise, display and handle a map. There is no separate window or similar for it, and thus, I figured that the class using an instance of Map would have to send any events separately to 'their' methods in the object. my question is, is this really necessary, or is there a possibility to register such events directly to the Map class?
    what I now have is something like this:
    public class Parent extends Applet implements KeyListener {
      Map m = new Map();
      public void init() {
        addKeyListener(this);
    //etc.
      public void keyPressed(KeyEvent e) {
        m.keyPressed(e);
    } //end of Applet
    class Map {
      public Map(){}
      public void keyPressed(KeyEvent e) {
        System.out.println("Recieved key event from Parent: "+e);
    }any wise suggestions?
    thanks in advance
    beaVer

    hell, it doesn't work yet. does anybody know what i'm doing wrong?
    public class TrivialApplet extends Applet implements KeyListener {
      Map m = new Map();
      public void init() {
        addKeyListener(m);
    //etc
    class Map implements KeyListener {
      public void keyPressed(KeyEvent e) {
        System.out.println(""+e.getKeyCode());
    }it simply doesn't work :/

  • Help with possible mouseEvent/Keyboard Event problem

    Hi guys, I am having trouble with a game I am creating right now.  The problem seems to lie on mouse / Keyboard event.
    Basically, I have a character that the player can control using the  keyboard arrow keys and it works perfectly fine on its own.  Whenever the game starts,  the player can control the character instantly with the keyboard. Here's the problem now, after I added another page (at frame 1) and created a start game button, those keyboard events  won't start immediately anymore.  The player must click on the stage  again before it works.  Is there any method to solve this?
    Right now, here is my Start button page.
    var start_btn:Start_btn = new Start_btn;
    start_btn.addEventListener (MouseEvent.CLICK, goGame);
    function goGame(event:MouseEvent) {
    gotoAndStop("game"); //The game's frame
    this.removeEventListener(MouseEvent.CLICK,goGame);
    Here's some code for the actual game part.
    stage.addEventListener(KeyboardEvent.KEY_DOWN,keyP  ressed);
    function keyPressed (e:KeyboardEvent) :void {
    //character movement code...like charcter.x++, x-- etc
    Thanks in advance

    How about trying:
         stage.focus = stage;
    in goGame().

  • 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");

  • Detect mouse clicks or keyboard events on desktop or everywhere

    Hi,
    What I have to do is to start the application minimized in the system tray. Then the application must be listening for crtl+shift+left mouse click in any part of the desktop or an opened application, when that happens, I have to show a window asking if the user want to take a screenshot starting in the x,y point he clicked and then take the screenshot.
    What I don't know how to do is to detect the mouse and keyboard events when the application is supposed to be running minimized in the system tray.
    How can I do that? Can anybody give me a hint?
    Thanks in advance.

    It's not possible with plain Java. You will need native code for this. Take a look at JNA.

  • Capture All Mouse and Keyboard events even if java window NOT in FOCUS

    Hi All,
    Is this possible to capture all mouse and keyboard events even if java window is not in focus or is minimized. This java program should cature each and every event from the user once the program is started. Any help in this regard is appreciated!
    Thanks&Regards
    Sam

    I don't think you can. (without JNI)

  • Lock all mouse and keyboard event.

    i am looking ways to lock up all the mouse and keyboard events in windows...do u guy have ways to solve this?

    Do you mean that people should not be able to start other applications, or switch to other running applications, before they have typed the right password into you java program? I don't think that can be done in java - it requires more control over the computer than Java typically gives you. You may have some success with full-screen AWT, though.
    But why not use log-on-systems incorporated in whatever operating system you are using? Or some other netware thingie? Honestly, I think you are trying to reinvent the wheel, and even with tool that's not very appropriate.

  • Dispatch loaded clip's keyboard event with parent's mouse click

    Hi. I'm building a swf wrapper which loads third-party swf games. The client would like a button in the wrapper which will dispatch a keyboard event in the loaded swf.
    Can anyone give me hand on how to construct a dispatch event in the wrapper that reaches into the loaded swf?
    Many thanks!

    after loading is complete:
    MovieClip(yourloader.content).dispatchEvent(new KeyboardEvent(somekeyboardevent));   // if the loaded swf is a movieclip

  • Pass Mouse click events from JavaScript to Falsh Movie

    Hi,
    I have an interesting problem here.
    i am trying to create a web page which has my
    flash-presentation movie. i need to disable mouse click &
    keyboard click navigation of the flash movie. The only way by which
    i can navigate my slide in the flash movie should be using 2
    buttons say Next & Prev that are i my web page.
    when i click the Next button i should be able to go to the
    next slid or the animation in the same slide like how i do in the
    power Point.
    Is there any way by which i can send these mouse click
    events from my javascript to my flash movie or is there any other
    means by which i can achieve this.
    ~Blackperil

    Hi Mathias,
    What i understood is that you want to triger a server side event (simulate onClick event of button)from a client side event (javascript confirm popup), based on the choice of user..
    You can also try this one...
    Check = confirm("Do you really want to proceed?");
    if (Check == true)
    document.getElementById('do_proceed').click();
    else
    document.getElementById('do_cancel').click();
    Regards,
    Anubhav

  • Take printscreen and detect mouse/keyboard input

    hi guys,
    I'm looking a way to take printsceen and detecting mouse/keyboard input in Adobe Air app using html/ajax .. is it possible ?
    any ideas ..please

    I wrote a blog post on how to do screen capturing using Adobe AIR abnd HTML/JavaScript. Maybe it'll help you out:
    http://www.andymatthews.net/read/2009/11/05/Capture-BitmapData-with-JavaScript-AIR-applica tions
    As for detecting key input, you can add a keydown/keydown event to the document quite easily.
    document.addEventListener('keydown', function(evt){
         // do something

  • Getting keyboard events on ALV grid

    Hi,
    I have an ALV Grid where it is possible to edit data. If user selects a row and presses delete/cut button with mouse event is triggered and I can access those events in code. Although if user selects a row and presses "Del" or "Ctrl + X" then I can't access those events in code. Is there a way to access keyboard events inside my code?

    Have a look at BCALV_GRID_EDIT -> if you select the first checkbox (p_cell = Update on cell change) then you will find that "data_changed" event can catch the line deletion via the keystrokes described.. in the event in this program, you could get the rows deleted from "rr_data_changed->mt_deleted_rows".
    if p_cell = 'X'.
      call method grid1->register_edit_event
        exporting
          i_event_id = cl_gui_alv_grid=>mc_evt_modified.
    else.
    Jonathan

  • [solved] send keyboard event / key to specific background window?

    Hi!
    So... is this possible / how? I'd like to send keyboard events to a window in the background - maybe even in regular intervals. While I'm dong something else, in another window (or nothing).
    Thx!
    Last edited by whoops (2011-07-21 11:05:44)

    Actually I'm thinking, maybe there is a totally another (better?) way to do what you want. I usually find that automatizing tasks in linux differs very much from the windows experinece, most of the times scripting is the most powerful and easy way of doing things. So if you describe to us what you want to accomplish, maybe some experienced linux gurus would give you some advices that sets you off course from sending keys and mouse events. I used to do that in windows with autohotkey, but now in linux there was no need for that so far ever, except for using system wide abbreviations with autokey.

  • 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.

Maybe you are looking for

  • Cant play purchased itunes videos on 5k iMac HDCP error

    After a few days of smooth sailing with my brand new 5k retina iMac I tried watching some purchased tv shows on itunes and I get this instead  "THE SELECTED VIDEO WILL NOT PLAY ON YOUR DISPLAY This movie can be played only on displays that support HD

  • Get price based on Good Received Qty

    Hi Experts, Do possible to determine price based on Good Received Qty instead of PO Qty? Eg: PO Qty 500 pcs = $ 5,000 1st GR - 150 pcs = price will determine $ 15 per pc 2nd GR - 350 pcs = price will determine $ 10 per pc Thanks in advanced..

  • ROLE in BI NetWeaver to EXECUTE queries

    Hello. I don't need any analisys authorizations. All I need to create one USER for all available queries execution. I guess there must be some ROLE in content or smthng. for query execution in BI for NetWeaver 2004s. Could anybody tell me the name of

  • Bug in Portal308 HLW Tutorial

    When you try to install the latest portal tutorial the import of hlw30_trl_sso.dmp fails with a "column not found" because the portal30_sso.wwutl_sso_transport_table$ and wwutl_sso_tx_person$ tables are missing the SUBSCRIBER_ID column. I altered the

  • Problem with my Macbook, do I need to update to 10.6?

    Hello, I am new in here, and I am typing as America Sign Lanuage. I hope you can understand what I am tying to say. I am stuck with Macbook Leopard, 10.5.8, I have this macbook for 4 years. (May 2009) I am starting have Freezing when I use firefox, s