Detect Key Press and Mouse Motion in ONE event?

Hi
I am trying to create a functionality where a mouse motion from left to right performs one action, and the same motion while a given key is pressed performs another action.
How can i combine the two events? How do I unify the KeyEvent and MouseEvent, particulary when I need to capture the directional motion of the mouse together with the key press?
many thanks for any insight

you cannot actualy combine them into 1 event but there is an easy way around this:boolean mouseKeyPressed = false;
public void keyPressed (KeyEvent e)
  if (e.getKeyCode () == ??) \\ or e.isCtrlDown(), e.isAltDown(), ...
    mouseKeyPressed = true;
public void keyReleased (KeyEvent e)
  if (e.getKeyCode () == ??) \\ or !e.isCtrlDown(), !e.isAltDown(), ...
    mouseKeyPressed = false;
public void mouseMoved (MouseEvent e)
  if (mouseKeyPressed)
    //processAction
}hope this helps,
greetz,
Stijn

Similar Messages

  • Reg: MouseListener and Mouse Motion Listener Interfaces

    Hi,
    Good day,
    I have added the mouselistener and mouse motion listeners to JButton..... With this i am trying to draw Circle and Line use mouse... When i was drawing at a particular point the actual drawn one is not placed at that point... so where can be error be present..how to overcome it.........
    Bye

    Insufficient information to find a solution. Please go through these links and respond accordingly.
    [How to ask questions the smart way|http://catb.org/~esr/faqs/smart-questions.html]
    SSCCE
    Use code tags to post codes -- [code]CODE[/code] will display asCODEOr click the CODE button and paste your code between the {code} tags that appear.
    db

  • How can I get mouse pressed and mouse released positions on the desktop whi

    Hello All,
    I am generating a Frame using Swing API. My requirement is I need to capture the mouse pressed and mouse released positions, whenever user drags the mouse on desktop region (i.e. outside of the Frame). I require these points to find the rectangle region user has generated starting from mouse pressed to mouse released position. I need to pass that rectangle to Robot class in order to capture that desktop region.
    Can anybody help me out how can I achieve this using java on MAC, Linux and Windows platforms?
    Thanks in advance.
    Regards,
    VPKVL

    VPKVL wrote:
    DarrylBurke wrote:
    Can't be done in Java.I don't think that there is something which can't be done using java. When searched over net, found few applications which are using java for implementing this feature but not free, asking for license fee. I checked by downloading the demo version.
    Just want to know the hint how it can be achieved so that I can move further on that lines.
    Your thoughts ?They use JNI with the OS API.

  • Dell 1950 power-edge III gen, key board and mouse stop after reboot using F1 key--Red hat 6.0

    I am trying to install OS (Red hat 6.0) in Dell 1950 power-edge III gen, After booting CD i got option to hit F1 to install or let is continue to start the installation process. now screen goes to next step and key board and mouse stop working .  it stop me from   further step. Please help 
    Sam

    Try booting to our live image and see if that lets you use the mouse and keyboard. http://linux.dell.com/files/openmanage-contributions/omsa-71-live/

  • IPhoto opens but then the spinning rainbow wheel appears and I can't do anything. I have opend iPhoto with the Option key pressed and rebuilt the library and it still happens.  I want to at least access my photos and copy them to an external drive.

    iPhoto opens but then the spinning rainbow wheel appears and I can't do anything. I have opend iPhoto with the Option key pressed and rebuilt the library and it still happens.  I want to at least access my photos and copy them to an external drive. Anyone have ideas on how to get to them?

    Make a temporary, backup copy (if you don't already have a backup copy) of the library and try the following:
    1 - delete the iPhoto preference file, com.apple.iPhoto.plist, that resides in your
         User/Home()/Library/ Preferences folder.
    2 - delete iPhoto's cache file, Cache.db, that is located in your
         User/Home()/Library/Caches/com.apple.iPhoto folder. 
    Click to view full size
    3 - launch iPhoto and try again.
    NOTE: If you're moved your library from its default location in your Home/Pictures folder you will have to point iPhoto to its new location when you next open iPhoto by holding down the Option key when launching iPhoto.  You'll also have to reset the iPhoto's various preferences.
    OT

  • Installed new hard drive in imac and i get folder with question mark, put in OS install disk and it does nothing? All I have is wireless key board and mouse, is this a factor?

    Installed new hard drive in imac and i get folder with question mark, put in OS install disk and it does nothing? All I have is wireless key board and mouse, is this an issue?

    Other than put disc in you don't give much info about what you've done. With the install disc inserted restart your Mac while holding the C key, that should start it up from the install disc. Should also work fine with a wireless Apple keyboard.

  • Track key press and key release on WPF applications

    Is there a way to track key press and release actions on WPF?
    This is what I've tried so far, but what I'm finding is that the _upDownKeyIsPressed is
    only set to false if I press another key - not when the up or down key is released.
    private void TrackUpDownKeyPress(KeyEventArgs e)
    if (e.Key == Key.Up || e.Key == Key.Down)
    // set to true if either up or down key is pressed
    _upDownKeyIsPressed = true;
    else
    // set to false once up or down key is released
    _upDownKeyIsPressed = false;
    private void PlotListView_KeyUp(object sender, KeyEventArgs e)
    TrackUpDownKeyPress(e);

    You want to track the Up and Down events. If you only use the Up event, then the variable will only be set to false when
    another key triggers the Up event:
    private void PlotListView_KeyUp(object sender, KeyEventArgs e)
    if (e.Key == Key.Up || e.Key == Key.Down)
    // set to true if either up or down key is pressed
    _upDownKeyIsPressed = true;
    private void PlotListView_KeyDown(object sender, KeyEventArgs e)
    if (e.Key == Key.Up || e.Key == Key.Down)
    // set to false if either up or down key is depressed
    _upDownKeyIsPressed = false;

  • Detecting Key Press at App Startup

    I would like to detect a press of the Shift key (ideally) when my application starts.
    If the user is pressing the key, display a normally hidden dialog allowing the user to select the language to use. If the key is not pressed, continue starting the application in the default language.
    From the Java Tutorial, it seems I can only detect a key press if the focus in on a GUI element is already visible. This defeats the purpose of having the special dialog be hidden.
    Any suggestions?

    From the Java Tutorial, it seems I can only detect a
    key press if the focus in on a GUI element is already
    visible. This defeats the purpose of having the
    special dialog be hidden.I believe this is because you are 'listening' for a key press from your GUI class
    Any suggestions?Sounds like you need to Listen for a key press in your running code
    you could try to give the GUI focus while still having it hidden(don't know if that would work)AND Make sure that you have your GUI and main APP in seperate threads. This would, of course, require a pause in your main app to change the language, so if you can get a key listener in your main app i think that would solve all probs.
    sorry if this sounds confusing

  • Detecting key press on Windows

    Hi! I want to do a program that can catch every key press in Windows, no matter in wich application the user is (nope... I'm not developing a virus for those of you who are thinking that)... does any one knows how to do this?
    Thanks!

    The technique is called "keyboard hooking" and you can search for the Windows API "SetHookWindowsEx". C and Windows API knowledge is mandatory.

  • Pairind an apple Key board and mouse from my Mac pro G5 to a newer Intel Xeon. Have OS 10.6.8 with all updates for Bluetooth. Still no luck setting up as new divice. Help.. Thanks Out There...

    I have an wireless Apple Keyboard and Mouse from my G5 Pro Mac, 2006. I would like to use it on a newer Intel xeon with blue tooth. Initally I was able to set them up.. Today Is another story. I have delete them as devices and have had no luck setting them up.. Help.. Many Thanks folks I am sure one of you good souls can help me out.. I have loaded the updates and am running 10.6.8. Are there issues using early apple wireless keyboards and a mouse.

    I have an wireless Apple Keyboard and Mouse from my G5 Pro Mac, 2006. I would like to use it on a newer Intel xeon with blue tooth. Initally I was able to set them up.. Today Is another story. I have delete them as devices and have had no luck setting them up.. Help.. Many Thanks folks I am sure one of you good souls can help me out.. I have loaded the updates and am running 10.6.8. Are there issues using early apple wireless keyboards and a mouse.

  • Key board and mouse don't function, key board and mouse don't function

    my laptop does not respond to the mouse or key board , i dont know how to solve my problem.If anyone knows hot to fix it let me know.It fuctions when i put a usb keyboard and mouse...

    I´m having the same problem. The mouse is the most problematic issue. The keyboar fails after working a while. The mouse sometimes loks up after a while, sometimes, it starts locked Up. I´ve tried to use a mouse driver under DOS, but it sometimes works, sometimes not (tried changing the mouse of course, same thing).
    MSI K7N2 Delta-L
    AMD 2600+Barton
    Ati radeon 9600Pro
    1x 256MB DDR 333 (dont have the brand)
    Western Digital Caviar 80 GB
    DVD AOPEN
    DVD RW ASUS
    PSU Unknown
    standar  five years old  keyboard
    A4 tech trackball

  • SOLVED Key board and mouse fail after last update

    Both my wireless keyboard and mouse failed after I updated yesterday. I'm using KNOPPIX to post they both work with knoppix so its not a hardware problem.
    KDE 4.1
    Logitech keyboard and mouse
    Last edited by normc (2008-11-08 00:05:37)

    Thanks a lot
    Just want to add that I had to edit grub at start up and add "single" at the end of the kernel line.
    The reason is that switching to runlevel 3 didn't work for me.

  • Help with  On key press and Frame

    Hi everybody,
    I have been trying to make this work but not able to. It would be of great help if u can tell where i am going wrong. Here is my code ( it is prety small) :
    I am trying to draw a random line when i do a keypress on the text field.
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    public class KeyPress extends Frame{
    Label label;
    TextField txtField;
    public static void main(String[] args) {
    KeyPress k = new KeyPress();
    public KeyPress(){
    super("Key Press Event Frame");
    Panel panel = new Panel();
    label = new Label();
    txtField = new TextField(20);
    txtField.addKeyListener(new MyKeyListener());
    add(label, BorderLayout.NORTH);
    panel.add(txtField, BorderLayout.CENTER);
    add(panel, BorderLayout.CENTER);
    addWindowListener(new WindowAdapter(){
    public void windowClosing(WindowEvent we){
    System.exit(0);
    setSize(400,400);
    setVisible(true);
    public class MyKeyListener extends KeyAdapter{
    public void keyPressed(KeyEvent ke){
    char i = ke.getKeyChar();
    String str = Character.toString(i);
    label.setText(str);
    Line2D myLine = new Line2D.Double(5,5,100,100);
    }

    Here's what I come up when I played with your code.
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import java.util.Random;
    public class KeyPress extends Frame {
        TextField txtField;
        Panel panel;
        public static void main(String[] args) {
            KeyPress k = new KeyPress();
        public KeyPress(){
            super("Key Press Event Frame");
            panel = new myCanvass();
            txtField = new TextField(20);
            txtField.addKeyListener(new MyKeyListener());
            panel.setBackground(Color.LIGHT_GRAY);
            add(txtField, BorderLayout.PAGE_END);
            add(panel, BorderLayout.CENTER);
            addWindowListener(new WindowAdapter(){
                public void windowClosing(WindowEvent we){
                    System.exit(0);
            setSize(400,400);
            setVisible(true);
        class myCanvass extends Panel {
            private Graphics2D g2;
            public void paint(Graphics g) {
                drawLine(g);
            private void drawLine(Graphics g) {
                g2 = (Graphics2D) g;
                g2.setColor(Color.RED);
                g2.draw(new Line2D.Double(Math.random() * 150, Math.random() * 150, Math.random() * 200, Math.random() * 200));
        class MyKeyListener extends KeyAdapter{
            public void keyPressed(KeyEvent ke){
                char i = ke.getKeyChar();
                String str = Character.toString(i);
                panel.repaint();
    }

  • Key board and mouse deactivated after reboot

    I am new Mac user. I have rebooted my apple laptop after that keyboard and mouse pad is deactivated

    Try booting to our live image and see if that lets you use the mouse and keyboard. http://linux.dell.com/files/openmanage-contributions/omsa-71-live/

  • Not Start up, Key board and Mouse not WORKING

    I have Pavilion G7-2017us Notebook and it has Windows 7 operation system. Symptom: Start the computer, go through to the windowns log-in page, but Keyboard and mouse are frozen, not WORKING. Can't log in. 
    force Poweroff computer and use ESC, F9 can go to system diagnose page, keyboard and mouse are WORKING now. Tried "Start-up test",
    Processor Check,Memory Test, Hard Disk SMART Check are Passed. Only Hard Disk Short DST is failed. Failure ID : GLMP00-69B7NV-MFPX1G-60SJ03
    So Start-up test is FAILED. Tried "System Tune-up", Processor Check,Hard Disk SMART Check are Passed. Only Hard Disk Short DST is failed.
    Failure ID : GLMP00-69B7NV-MFPX1G-60SJ03.So System Tune-up Is FAILED. Tried "Hard Disk Test", Hard Disk SMART Check is Passed and Only Hard Disk Short DST is failed.Failure ID : GLMP00-69B7NV-MFPX1G-60SJ03.
    So Hard Disk Test Is FAILED. When I performed above test, keyboard and mouse were WORKING properly. Tried Safe mode, but can not log-in because keyboard and mouse are not working at that time. I cared about documents and was able to copy some files to external harddisk under DOS command interface. But right now I can not adjust
    this laptop back to normal DOS from safe mode log-in. When I started up it. it goes through to log-in page in Safe mode. Also F11 is not
    working because I did not make system recovery point and it can not be recoveried. Please help me for this issue. Thank you very much.

    Thank you, Visruth.    When you said the failure ID indicates failling or failed HDD, do you mean that the old HDD is bad and probably all the data on it will be lost ?    Yes, in order to salvage data from the old HDD,  I have tried to buy an external enclosure and take that harddrive out to make an external hard drive. Connect it through USB , but the new laptop can not recognize it and I can see this external hard drive shown in the device manager, but I can not see more detailed information of that drive. Click it and it asks that do you want to format that drive?      So I would like to salvage data from the old HDD. I have been able to enter into DOS command in the old laptop and copied all data on my desktop in C drive. But right now I have forced this old laptop to run into safe mode, which I think maybe I have a chance. But keyboard and mouse are still frozen at log-in page. I do not know how to get back to DOS command as I did before. If I can go back to DOS command, I may use DOS Xcopy to copy out all my data in the old HDD to new external drive. Would you please show me how to get back to DOS command from safe mode log in? I have tried F8, F9. no success.   Another way I am thinking is that to take the old HDD as an external drive, connect to a new laptop, change that new laptop's start up sequence, put the USB external drive start up as the first choice. I really do not know why my keyboard and mouse in the old laoptop do not work at some time (log-in page). Please let me know your advice. Thank you very much. 

Maybe you are looking for

  • Play count on one song didn't register today?

    Hello, Play counts are very important to me for a few reasons, but today I listed to the same song at least 4 times today at work and when I synched my iPod with iTunes the song said "Last played - 7/5/07" when clearly that isn't the case. I do know

  • Calling a function in an EXE file from Java Program

    Hi Im having a function which is written in c program.i need to call that function from my java program, if i create a shared library (DLL) for my C code then it works but my requirement is i dont want to create that DLL , like in it would be an exec

  • Access request creation - select roles screen - field boxes were not aligned

    I'm not sure if this is really the screen of SAP GRC 10.1 access request creation. The field boxes were not aligned. Is there a note to fix this issue? Thank you. Regards, Jenilyn

  • Windows 8.1 sound problem

    Hello! I have NVidia HD Sound Drivers installed. My sound worked fine on Windows 8. It also worked fine after I updated to windows 8.1, but after a while the sound disappeared. In device manager, it sais the drivers are installed but the system can n

  • Mail (gmail account) constantly asking for password

    Hello, My wife has a 3gs She originally setup her mail using the phones built in gmail account step by step method. While using this, her phone was constantly saying it could not access the gmail server. So, I setup her mail with gmail using the goog