Swap Mouse Button Click

hi, I am working on some application and i got this problem, i have this EventHandler class and all my application event pass through this class, now what i want to do is, i want to swap the events on mouse click, like when user press mouse left click i want to change this even as right click, this will basically depands on user choice, so is there any possible way to change the event behaviour or to sawap mouse right click as in left and left as in right?
here is my code,
public class MyEventQueueHandler extends EventQueue {
  private boolean MacOs  =  Myapp.macOS();
  protected void dispatchEvent(AWTEvent event) {
    if(MacOs) super.dispatchEvent(event);
    else
    if(event instanceof KeyEvent) {
      if(System.currentTimeMillis() - ((KeyEvent)event).getWhen() <= 1000)
      super.dispatchEvent(event);
      else ((KeyEvent) event).consume();
    } else
    if(event instanceof MouseEvent) {
        if(SwingUtilities.isRightMouseButton((MouseEvent)event))
              if(pref)
            ///here i wants to do something ,which passes this is as mouse  left event                
      if(System.currentTimeMillis() - ((MouseEvent)event).getWhen() <= 1000)
      super.dispatchEvent(event);
      else ((MouseEvent) event).consume();
    } else
    super.dispatchEvent(event);
if anyone can help with this thing...many thanks.

could be a simple as separating the code from the event and using
the various conditions to call the approriate code?
something like this (mouse click in the panel)
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Testing
  JLabel label = new JLabel("");
  boolean swapButtons = false;
  public void buildGUI()
    JPanel p = new JPanel();
    p.add(label);
    p.setPreferredSize(new Dimension(600,400));
    JPanel p1 = new JPanel();
    final JCheckBox cbx = new JCheckBox("Swap Buttons");
    p1.add(cbx);
    JFrame f = new JFrame();
    f.getContentPane().add(p,BorderLayout.CENTER);
    f.getContentPane().add(p1,BorderLayout.SOUTH);
    f.pack();
    f.setLocationRelativeTo(null);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
    p.addMouseListener(new MouseAdapter(){
      public void mousePressed(MouseEvent me){
        if(SwingUtilities.isRightMouseButton(me)){
          if(cbx.isSelected()) leftClickCode();
          else rightClickCode();
        else if(SwingUtilities.isLeftMouseButton(me)){
          if(cbx.isSelected()) rightClickCode();
          else leftClickCode();
  public void leftClickCode()
    label.setText("leftClickCode");
  public void rightClickCode()
    label.setText("rightClickCode");
  public static void main(String[] args)
    SwingUtilities.invokeLater(new Runnable(){
      public void run(){
        new Testing().buildGUI();
}

Similar Messages

  • Identify left and right mouse button clicks?

    I am wondering how is it possible to identify left mouse button click and right mouse button click using Java rather than just identify a mouse click.
    Kumar

    I'm not sure if this is what you mean, but you can use MouseEvent's getButton() function.
    For example
    class MyListener implements MouseListener
        public void mousePressed(MouseEvent e)
            int btn = e.getButton();
            //btn = 1 (left button), btn=2 (right button) for 2 button mouse and so on...
    }

  • Script center mouse button click?

    Can anyone tell me how to script a click on the mighty mouse roller ball? I have click on the roller ball/center mouse button set to bring up the Application Switcher. What I like about this method of bringing up Application Switcher is that it remains on screen without having to hold any keys down. I am hoping that a script that tells the system to center mouse button click will bring launch Application Switcher such that it stays on screen.
    THx
    ~Von

    you can't possibly script something like that. you have to consult the documentation for your mouse to see if it lets you reassign the button functions to do this. start with system preferences->keyboard and mouse->mouse. also some 3rd party mouse drivers like USB overdrive will probably let you do this
    http://www.versiontracker.com/dyn/moreinfo/macosx/13443

  • Firefox 4 middle mouse button click acts different from v3

    clicking on the middle mouse button (not scrolling) acts like "open link in duplicated tab" rather than how it used to act like "open link in new tab".
    It places the new tab at the bottom/end of the list of tabs rather than how it used to as a child of the tab in which the middle button was clicked.
    Is there an option to change this behavior?

    jscher2000: THANK YOU. The thread was doubly useful.
    1. I had the same problem to cor-el's post to "Set the pref browser.tabs.insertRelatedAfterCurrent to true on the about:config page" as orwel had: it will not be changed.
    2. I disabled my addons one by one and found that THE PROBLEM WAS with Duplicate This Tab 1.2 When it is disabled, the center mouse click works as it used to -- and I assume this means 'correctly'. Certainly it's the way I want it to work:-)
    3. I am new to this support path. If you think the information I just posted can help those on the thread you pointed to, and you are so inclined, please inform them about Duplicate This Tab 1.2 should anyone there be using it.

  • Flash Island: right mouse button click will trigger a refresh of Flash

    Dear all,
    I'm trying the example IslandsWDATutorial1 (bar chart) http://wiki.sdn.sap.com/wiki/display/EmTech/IslandsWDATutorial1
    I found when I click right mouse button (or  context menu button on keyboard) in web dynpro area, the flash (bar chart) will refresh.
    I debugged but can't find the reason. Does anyone know how to prevent this refresh?
    Thanks for your help
    Donny

    Currently the XML for the Island is not delta handled. It is resent to the FlashIsland on any event. Although the Flash Player isn't recreated on these events, the data is rebound to the UI controls  - causing linked animations to replay. 
    This was recently discussed on the forum and I created a prototype implementation of a possible delta handler mechanism for the Islands XML.  It creates a stable Island when there are no changes that impact the context(s) bound to the Island. This has been turned over to development and they will consider it for the next development sprint. Likely this functionality won't make its way into the product until the next enhancement package, however.

  • Tooltip when mouse button clicked

    Hi there
    I am trying to display dinamic tooltips messages whenever the right mouse button is clicked.
    Any idea??
    Thanks

    Hi,
    Do u want to ...display the tooltip text wherever hte mouse clicks or ...do u want to display the text witin any specfied label?.............or else u can do one thing ...create one lable...and equal the label position with the mouse position...whenever mouse is clicked set the label with whatver string u want using setToolTip() method?............or do u have any other questions? reply back!

  • Trackpad mouse-button click

    My mouse button on my MacBook has broken on the right side. You have to push it really hard for it to work. Now the left side of it is getting where it does always respond the first time I click it. And sometimes i click once and it double-clicks on its own. Do I need to send it in for service or what, I have the 3 year protection plan. Will it be fixed for free because I have that?

    Send it in. Your machine is under warranty so you can get it fixed for free.
    I know some people with this problem have just bent the underside of the button or something like that to fix this but why risk this or put up with the problem if its under warranty.

  • Envy m4 - mouse button clicking

    I have an HP Envy m4 which was puchased in April 2013. Within the last few days the left button of my mouse pad has started to click when I tap it.  It seems like it's getting stuck but nothing has spilled on it and it's not dirty.  It's not depressing at the same level from one side of the button to the other like the right button.  Almost like something broke below it?  What can I do to correct this? Thanks!

    Hi Zekemon,
    The only way to inspect the touchpad assembly would be to disassemble the Notebook. You could try using compressed air around the touchpad surface when the system is powered off but it is doubtful this will help. It is possible some dust has accumulated under the touchpad.
    An HP tech or a qualified tech in your locale would have to disassemble the Notebook and inspect for dust or damage.
    Are you under warranty? Then I recommend contacting HP Support for service.
    Please see here for six possible matches for an Envy m4. Select your product, select "Contact HP", and select a support option.
    Jaco
    ****I am not an HP employee****
    Please give a" Kudos, Thumbs Up" if advice received is relevant or" Accept as Solution" to assist other forum users having a similar problem.
    HP Products:
    810-150se Desktop
    17t-j000 Notebook
    H8 1380t CTO Desktop
    560z Desktop
    Errare humanum est.

  • Right mouse button click in a JTree leaf

    Hi,
    how can I add a mouse listener in a JTree leaf? I have DOM nodes wrapped and a JTree model adapter to set up the JTree. I want the popup menu to show everytime the user clicks on a leaf, but not on the tree itself.
    Thanks!

    Really you just have to add your listener to the tree itself, then use the Point to find the corresponding TreePath (getPathForLocation), from which you'll easily find the node.

  • Recognizing both mouse buttons clicked

    hey everyone!
    thats my first post here..
    as a student, i'm making a JAVA-based project for my final exams this year.
    my project is a minesweeper game, yep, just like microsoft's one, only JAVA-based.
    i want my mouselistener to recognize when i click BOTH left button and right button on a JButton, and when releasing at least one of them do some commands that i will program by myself already..
    the only thing is i don't have a clue how to make my mouselistener recognize that.. any help please?
    thanks!!

    In mouseReleased(MouseEvent) you can check the extended modifiers using getModifiersEx() to see if the opposite button (the one not being released) is held down. For example, if the BUTTON1 is released check for BUTTON2_DOWN_MASK in the extended modifiers. If this is the case then you know that both buttons were down and the user just released BUTTON1. Check for BUTTON1_DOWN_MASK if the button is BUTTON2 and you know that both buttons were down and the user just released BUTTON2.

  • Is it possible to create a context menu, which is launched by right mouse button click event?

    The question is following: when you are pushing right button in the window of a working vi you see the build-in context menu of labview. Is it possible to customize it, or create the new one?
    www.xinstruments.com
    Custom Software for Industrial Automation
    www.hdrconverter.com
    Picture processing made easy

    There's no nuilt-in LabVIEW function or tool to do it, but Dave Ritter published an artical in the LabVIEW Technical Resource last year that described how to do this. It uses the Event Structure so you need to have at least LabVIEW 6.1.
    You can read a bit of the artical here. There's also a link on the bottom of the page where you can purchase that issue to get the entire artical and sample code.
    Ed
    Ed Dickens - Certified LabVIEW Architect - DISTek Integration, Inc. - NI Certified Alliance Partner
    Using the Abort button to stop your VI is like using a tree to stop your car. It works, but there may be consequences.

  • The right mouse button on my 8740w has failed (clicks but no result, i.e Cut/Copy/Paste/Delete menu

    My right mouse button clicks but no result, i.e Cut/Copy/Paste/Delete menu does not appear.
    I think the hardware has failed.
    Note the mousepd is not the issue.  The right button is the problem
    Left button works fine

    Same deal with me except the right button has failed twice. You may find that if you push on it past the click with a bit more force it will respond. They swapped the hardware and same thing occurred.
    HP should be ashamed that they would put such awful mouse hardware on its flagship product. Whoever designed it should be fired.
    If HP had any customer loyalty they would offer a hardware update and offer it to those who are still under warranty.
    Suffice to say I will never, ever purchase an HP workstation again.
    Good luck.

  • Evdev kills X with mouse buttons

    Hi
    I'm new to Arch so please have some patience.
    I have a Logitech MX3100 mouse/kbd combo (MX1000 mouse), connected via usb
    I just installed Arch yesterday and to get all my mouse buttons working I tried to use evdev, now the problem is if I use evdev, X crash instantly with any mouse button click other than button1. If I don't specify the event (as documented in the wiki) the mouse doesn't work at all.
    Section "InputDevice"
    Identifier "Evdev Mouse"
    Driver "evdev"
    Option "device" "/dev/input/event5"
    # Option "Name" "Logitech USB Reciever"
    Option "SendCoreEvents" #CorePointer"
    Option "Buttons" "12"
    EndSection
    This is the backtrace from log
    Backtrace:
    0: X(xf86SigHandler+0x7e) [0x80d9e0e]
    1: [0xb7fdc420]
    2: /usr/lib/xorg/modules/input//evdev_drv.so [0xb722d8bd]
    3: X [0x80d9f8a]
    4: X [0x80b4fb6]
    5: [0xb7fdc420]
    6: X(Dispatch+0x82) [0x808c602]
    7: X(main+0x48b) [0x8073d5b]
    8: /lib/libc.so.6(__libc_start_main+0xe0) [0xb7db7390]
    9: X(FontFileCompleteXLFD+0x201) [0x80730d1]
    Other interesting parts of the log:
    (**) Evdev Mouse: always reports core events
    (II) Evdev Mouse: Found 4 relative axes.
    (II) Evdev Mouse: Configuring as pointer.
    (EE) Evdev Mouse: Unable to parse 'null' as a map specifier string.
    (EE) Evdev Mouse: Unable to parse 'null' as a map specifier string.
    (EE) Evdev Mouse: Unable to parse 'null' as a map specifier string.
    (EE) Evdev Mouse: Unable to parse 'null' as a map specifier string.
    (EE) Evdev Mouse: Unable to parse 'null' as a map specifier string.
    (EE) Evdev Mouse: Unable to parse 'null' as a map specifier string.
    (EE) Evdev Mouse: Unable to parse 'null' as a map specifier string.
    (EE) Evdev Mouse: Unable to parse 'null' as a map specifier string.
    (EE) Evdev Mouse: Unable to parse 'null' as a map specifier string.
    (EE) Evdev Mouse: Unable to parse 'null' as a map specifier string.
    (EE) Evdev Mouse: Unable to parse 'null' as a map specifier string.
    (EE) Evdev Mouse: Unable to parse 'null' as a map specifier string.
    (EE) Evdev Mouse: Unable to parse 'null' as a map specifier string.
    (EE) Evdev Mouse: Unable to parse 'null' as a map specifier string.
    (EE) Evdev Mouse: Unable to parse 'null' as a map specifier string.
    (EE) Evdev Mouse: Unable to parse 'null' as a map specifier string.
    (EE) Evdev Mouse: Button(null)MapTo: Button 96 already claimed.
    (EE) Evdev Mouse: Unable to parse 'Button 96' as a map specifier.
    (II) Evdev Mouse: Found 96 mouse buttons
    (II) Evdev Mouse: Configured 96 mouse buttons.
    (**) Option "CorePointer"
    (**) USB Mouse: always reports core events
    (II) USB Mouse: Found 4 relative axes.
    (II) USB Mouse: Configuring as pointer.
    (EE) USB Mouse: Unable to parse 'null' as a map specifier string.
    (EE) USB Mouse: Unable to parse 'null' as a map specifier string.
    (EE) USB Mouse: Unable to parse 'null' as a map specifier string.
    (EE) USB Mouse: Unable to parse 'null' as a map specifier string.
    (EE) USB Mouse: Unable to parse 'null' as a map specifier string.
    (EE) USB Mouse: Unable to parse 'null' as a map specifier string.
    (EE) USB Mouse: Unable to parse 'null' as a map specifier string.
    (EE) USB Mouse: Unable to parse 'null' as a map specifier string.
    (EE) USB Mouse: Unable to parse 'null' as a map specifier string.
    (EE) USB Mouse: Unable to parse 'null' as a map specifier string.
    (EE) USB Mouse: Unable to parse 'null' as a map specifier string.
    (EE) USB Mouse: Unable to parse 'null' as a map specifier string.
    (EE) USB Mouse: Unable to parse 'null' as a map specifier string.
    (EE) USB Mouse: Unable to parse 'null' as a map specifier string.
    (EE) USB Mouse: Unable to parse 'null' as a map specifier string.
    (EE) USB Mouse: Unable to parse 'null' as a map specifier string.
    (EE) USB Mouse: Button(null)MapTo: Button 96 already claimed.
    (EE) USB Mouse: Unable to parse 'Button 96' as a map specifier.
    (II) USB Mouse: Found 96 mouse buttons
    (II) USB Mouse: Configured 96 mouse buttons.
    (II) evaluating device (USB Mouse)
    (II) XINPUT: Adding extended input device "USB Mouse" (type: KEYBOARD)
    (II) evaluating device (Evdev Mouse)
    (II) XINPUT: Adding extended input device "Evdev Mouse" (type: KEYBOARD)
    (II) evaluating device (Keyboard0)
    (II) XINPUT: Adding extended input device "Keyboard0" (type: KEYBOARD)
    (**) USB Mouse: 2 valuators.
    (**) USB Mouse: Configuring in Absolute mode.
    (**) USB Mouse: Registering 96 buttons.
    evdev: leds are 0x0 for device 2
    (II) USB Mouse: Init
    (**) Evdev Mouse: 2 valuators.
    (**) Evdev Mouse: Configuring in Absolute mode.
    (**) Evdev Mouse: Registering 96 buttons.
    evdev: leds are 0x0 for device 3
    (II) Evdev Mouse: Init
    (II) USB Mouse: On
    (II) Evdev Mouse: On
    (EE) Evdev Mouse: Unable to grab device (Device or resource busy).

    Hi Eradest,
    I guess there is some confusion since it's a mouse/kbd combo, it creates 2 events, one for the keyboard og 1 for the mouse, and the tricky part is that the one for the mouse also features some extra keyboard keys.
    I tried your suggestion, but still same result, if I don't specify event, then the mouse doesn't work.
    If I comment out both mouse and keyboard X autodetect it and use evdev for both it seems, however then I have the problem that X crash when I click any other mouse button than button1
    I've also tried using the default keyboard setting and let X autodetect it, but it makes no difference.
    This is the part of my xorg.conf
    Section "ServerLayout"
    Identifier "Xorg Configured"
    Screen 0 "Screen0" 0 0
    # InputDevice "Keyboard0" "CoreKeyboard"
    InputDevice "Mouse" "CorePointer"
    # InputDevice "Evdev Mouse" "SendCoreEvents" #"CorePointer"
    # Serial Mouse not detected
    # USB Mouse not detected
    EndSection
    Section "InputDevice"
    Identifier "Evdev Mouse"
    Driver "evdev"
    # Option "device" "/dev/input/event6"
    Option "Name" "Logitech USB Reciever"
    # Option "SendCoreEvents"
    Option "CorePointer"
    Option "Buttons" "12"
    EndSection
    Last edited by kayrune (2007-12-15 19:11:41)

  • In UNIX middle mouse button pastes clipboard text to noneditable JTextField

    In UNIX, if you have a JTextField which is not editable, i.e. setEditable(false), clipboard text can still be pasted to the JTextField if the middle mouse button is pressed. How can I prevent this?
    I've tried overriding the JTextComponent paste() method,but that only works if the user hits CTRL-V, but not for the middle mouse button click. A GlassPane works but blocks all events for the entire frame.
    How do I prevent middle mouse button clicks from pasting into a noneditable JTextField?

    This is actually a bug in java that has been reported and fixed so in the next release i would expect that it will work. We found the bug about 8 months ago and reported it and have since recieved email from sun saying the bug has been fixed. They had a similar problem with the CTRL-V paste before and fixed it but apparently forgot to fix the unix based middle click paste. We decided that the bug wasn't something we needed to fix so we never investigated a work around for it.

  • I can't remove Yandex Elements from the Open menu list with right mouse button and Tools menu although I removed Yandex. I think it slows down Firefox.

    I downloaded Freeyoutube downloader from internet and somehow got yandex installed in my computer with toolbars on firefox.Despite I removed Yandex from my computer Yandex elements still stays in open menu when right mouse button clicked and in the Tools menu. I tried to uninstall Firefox, remove yandex registry from windows registry and restart computer, and then reinstall firefox, Yandex elements still hangs there. Firefox is now running very slow compared to the running before Yandex.

    hello, please try all these steps:
    # [[Reset Firefox – easily fix most problems|reset firefox]] (this will keep your bookmarks and passwords)
    # afterwards go to the firefox menu [[Image:New Fx Menu]] > addons > extensions and in case there are still extensions listed there, disable them.
    # finally run a full scan of your system with different security tools like the [http://www.malwarebytes.org/products/malwarebytes_free free version of malwarebytes] and [http://www.bleepingcomputer.com/download/adwcleaner/ adwcleaner] to make sure that adware isn't present in other places of your system as well.
    [[Troubleshoot Firefox issues caused by malware]]

Maybe you are looking for