Key binding won't work with alt-up and alt-left arrow combined

I was playing with key binding trying to create a small app where a timer is started with the press of an alt-arrow key and stopped when the key is released. The timers append Strings to a JTextArea telling which alt-arrow key is currently pressed.
This program works, and in fact if you press a combination of any two keys, both timers will work simultaneously, that is unless you press both up arrow and left arrow together. Can anyone see a bug in the program that explains why it won't work for these two particular keys when combined? Thanks in advance, Pete
My SSCCE,
KeyBindingEg.java
package javaforum2009;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import javax.swing.*;
public class KeyBindingEg {
  // parallel arrays -- sorry
  private static final int[] ARROW_KEYS = {
      KeyEvent.VK_UP, KeyEvent.VK_DOWN,
      KeyEvent.VK_LEFT, KeyEvent.VK_RIGHT };
  private static final String[] ACTION_STRINGS = {
    "Up", "Down",
    "Left", "Right" };
  private static final String PRESSED = "PRESSED";
  private static final String RELEASED = "RELEASED";
  private static final int TIMER_DELAY = 100;
  private JPanel mainPanel = new JPanel();
  private JTextArea textArea = new JTextArea(20, 30);
  public KeyBindingEg() {
    JPanel northPanel = new JPanel();
    northPanel.add(new JLabel("This JTextField has the focus: "));
    northPanel.add(new JTextField(10));
    textArea.setEditable(false);
    mainPanel.setLayout(new BorderLayout());
    mainPanel.add(northPanel, BorderLayout.NORTH);
    mainPanel.add(new JScrollPane(textArea), BorderLayout.CENTER);
    setBindings();
  private void setBindings() {
    int context = JComponent.WHEN_IN_FOCUSED_WINDOW;
    InputMap inputMap = mainPanel.getInputMap(context);
    ActionMap actionMap = mainPanel.getActionMap();
    for (int i = 0; i < ARROW_KEYS.length; i++) {
      // timer is started on key press and stopped
      // on key release.
      Timer timer = new Timer(TIMER_DELAY, new KeyTimerListener(
          ACTION_STRINGS));
timer.setInitialDelay(0);
// get input maps for all alt-arrow keys for both key press
// and key release
inputMap.put(KeyStroke.getKeyStroke(ARROW_KEYS[i],
InputEvent.ALT_DOWN_MASK, false), ACTION_STRINGS[i] + PRESSED);
inputMap.put(KeyStroke.getKeyStroke(ARROW_KEYS[i],
InputEvent.ALT_DOWN_MASK, true), ACTION_STRINGS[i] + RELEASED);
// set corresponding actions for the two different key presses above
actionMap.put(ACTION_STRINGS[i] + PRESSED, new ArrowKeyAction(false, timer));
actionMap.put(ACTION_STRINGS[i] + RELEASED, new ArrowKeyAction(true, timer));
@SuppressWarnings("serial")
private class ArrowKeyAction extends AbstractAction {
private boolean onKeyRelease;
private Timer swingTimer;
public ArrowKeyAction(boolean onKeyRelease, Timer swingTimer) {
this.onKeyRelease = onKeyRelease;
this.swingTimer = swingTimer;
public void actionPerformed(ActionEvent arg0) {
if (onKeyRelease) {
swingTimer.stop();
} else {
swingTimer.start();
private class KeyTimerListener implements ActionListener {
private String actionString;
public KeyTimerListener(String actionString) {
this.actionString = actionString;
public void actionPerformed(ActionEvent arg0) {
textArea.append(actionString + " pressed\n");
public JComponent getPanel() {
return mainPanel;
private static void createAndShowGUI() {
JFrame frame = new JFrame("KeyBindings Example");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new KeyBindingEg().getPanel());
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();

camickr wrote:
I noticed the problem a while ago with a similiar example and asked the same question to which nobody could give an explanation. The same observations seem to apply to your example in that using the numpad arrow keys work without a problem.
[http://forums.sun.com/thread.jspa?threadID=5176816]
Yes indeed. I suppose (as always) I should have searched the forum first before asking the question. Thanks for the link and info.
/Pete

Similar Messages

  • Safari won't work with CNN Pipeline and other sites all of a sudden?

    Safari won't work with CNN Pipeline and other sites all of a sudden? A few weeks ago Safari was working OK but now I often have to use Firefox to visit certain webpages.
    Anyone else having this same problem?
    Is there a quick fix?
    I'm using Safari 2.0.4
    Thanks.

    Hi QuickTimeKirk,
    I have WMP version 9, as well. I do not use F4M, for many users f4mac is what helps.
    I find some items work while others do not. I always get an alert about the wmp , which version it is, takes very long to load, I find it is not consistant with Safari, as seems the poster of this topic has found.
    Quoted from ms Mactopia site:
    http://www.microsoft.com/windows/windowsmedia/player/mac/
    Download and find information about Windows Media Player for Mac and playing Windows Media files in your QuickTime Player. Which download is right for you?
    Windows Media Components for QuickTime
    Windows Media Player 9 for Mac OS X
    Windows Media Player 7.1 for Mac
    Important Information
    Microsoft will continue to offer Windows Media Player for Mac as a download free of charge, but has no plans to provide future updates or product support.
    We are pleased to offer Windows Media® Components for Quicktime, by Flip4Mac™, as an alternative for Mac OS X users wanting to play Windows Media Audio and Windows Media Video.
    ~•~
    Validation of the cnn home page using the W3C Validatior, http://validator.w3.org/
    http://validator.w3.org/check?uri=http%3A%2F%2Fwww.cnn.com%2F
    though 41 errors is not as poor as some, Firefox handles the site better than Safari, imo.
    Some sites just work better with Firefox or an other browser.
    Cheers,
    Eme '~[ )

  • Airplay won't work with Apple TV and iPad 2

    I have an iPad 2 running iOS 8.1 and an Apple TV 3 with the latest software and I can't use Airplay to send content to my Apple TV. I know there is no issue with the Apple TV since I can use Airplay to send content to my Apple TV using my iPhone 6, and Macbook, but not using my iPad. Oddly, Airplay will work on my iPad when I connect to my airport express, but not to my Apple TV - Apple TV doesn't appear in the drop down menu yet my airport express does! I have gone through all the usual fixes (restarting, restoring, etc. etc.) - to no avail, my iPad simply can not find my Apple TV for some reason. Any help would be greatly appreciated! cheers, d

    I Have the same problem with iOS 8.2 and the latest OS for the Apple TV. My Apple TV is connected by ethernet as is my iMac. I can stream to the Apple TV from my iMac via this ethernet setup. But my iPad and iPhone 5s with iOS 8.2 won't connect even though I can see the AirPlay button and the sound a pics go blank on the iPhone and iPad .
    I Have been suing AirPlay for several years with no prob,ms until now. I am running Yosemite OS on the iMac.

  • I am running Firefox 5, McAfee Site advisor is blocked. I contacted McAfee and they said it won't work with Firefox 5 and that I should use an ealier version of FF or use IE. Is there a patch coming to allow Site Advisor to work on FF 5?

    As above McAfee apparently feels the fault is with FF. I will admit that under the latest 3 version it worked fine. I skipped version 4 because of some things a read about it. I did go with FF5.

    The McAfee Site Advisor add-on is blocklisted by Mozilla due to that Site Advisor extension being the #2 cause of crashing the Firefox 5.0 betas. McAfee was notified of the problem long before that extension was added to the blocklist. Now it is up to them to fix it. <br /> https://addons.mozilla.org/en-US/firefox/blocked/ <br />
    https://bugzilla.mozilla.org/show_bug.cgi?id=660111
    I have read that McAfee is working on a re-written version that is projected to be available in the 3rd week of July.
    Quite honestly, with McAfee taking the position that this problem is with Firefox or is Mozilla's fault, when that add-on has a long history of being [http://kb.mozillazine.org/Problematic_extensions PROBLEMATIC], I have lost the little respect I had for McAfee being a respectable, ethical company. ''Of course, my level of respect for McAfee was low to begin with due to problems I had with their software 10 years ago causing me to re-format my PC bi-weekly immediately after their security scans on a Win98 PC, and haven't used their stuff since once I discovered their software was causing my problem with lost video card drivers repeatedly.''

  • Satellite A300 - inbuilt Chicony webcam won't work with Win Live Messenger

    Hello
    I just bought a *Satellite A300-1MC* (runs on Vista Home Premium), and downloaded Windows Live Mail And Live Messenger.
    The inbuilt webcam won't work with Live Messenger ; and when selecting Tool, Audi + Vieo Setup in Messenger I get thye following message : "We are unable to run Audi Video setup".
    The webcam works fine with the Camera Assisant Software.
    I have tried : 1) killing the C.A. Software and starting Messenger ; 2) dowanloading a webcam driver from Toshiba website ; 3) Updating Windows Vista
    None of the above work.
    Any suggestion gladly received.....
    Thomas

    Hi,
    Many thanks for the advice.
    I have downloaded and installed ManyCam 2.3, then rebooted.
    The ManyCam software works fine, and picks up signal from the inbuild webcam.
    But Windows Live Messenger still doesn't pick up the camera. I can not start a Video call or go to" Video Audio setup".
    I have Windows Live Messenger version 14.0.8064 (installed on Tuesday).
    Funny enough, yahoo messenger works fine : it gets a signal from the webcam.
    Conclusion : i think it is Windows Live Messenger that doesn't work properly for some reason.
    I have ordered a new external webcam, in the meantime.
    Thomas

  • Hi my iMac has decided to come up for the 5 time Work the ?  Symbol just tris time everytime i try to restart the iMac with any key it won't work, then I try also i knserted the installation dvd and it does not, If media is getting scratched in the drive

    Hi my iMac has decided to come up for the 5 time With the ?question mark   Symbol just this time when i try to restart the iMac with any key it won't work, then I try also to insert the installation dvd and stard with yhe C or D key
    Still no way to grt it starting, also I notice the DVD drive is getting scratched in the drive just before it outomaticly ejected.
    media is getting scratched after been used and ejected by my iMac without loading .
    Please help!!! I  to finish my college work and have no way of  work on it! HELP
    Thanks

    Boot off your *original* Install Disk while holding down the *d key*, (not c key), then run the extended Apple Hardware Test. Some disks require you to use the Option key at bootup to select AHT. Some models have a separate AHT CD. Some have it on the Disc #2.
    The Memory test can really only be trusted if it finds a problem, not if it doesn't find a problem.
    Memtest OS X...
    http://www.memtestosx.org/joomla/index.php
    Rember is a freeware GUI for the memtest ...
    http://tech.kateva.org/2005/10/rember-freeware-memory-test-utility.html

  • Intuit's Quicken won't work with Lion.  Installed and am using Quicken Essentials but it's not as convenient.

    Intuit's Quicken won't work with Lion.  Installed and am using Quicken Essentials but it's not as convenient.

    this has been an issue with Quicken for a long time! Quicken was initially a Mac only application and then they got greedy! i beta-tested Quicken for Intuit for years and when they announced they were not going to support it any more the screaming was loud but not heard!
    Quicken Essentials is a crime! i wasn't even asked to beta-test it; probably because they would have gotten an earful!!! it is not essential; it is stupid.... AND, of course, their online version was a disaster. i use Quickbooks Online for business and it works like a charm; i mean it even downloads ignominious PayPal transactions now!
    i am also stupid for not really checking out if it would work with Lion - ALL of my financials are on it. I am going to have to do what @cwiens suggested above and either pull out an old Macbook I have or my well stored original Cube in its original box! thank the fates for the double backup i've always done with Quicken - Time Machine & its own key drive!
    btw, this is an old Microsoft trick - not having older versions of apps work on OS updates so they force you to buy the new versions.

  • IMessage won't work with 1 contact. (iOS7)

    iPhone 4s with iOS7
    iMessage won't work with only 1 specific contact.
    Prior to updating i was able to iMessage with the contact in question without issue.
    Both of us updated to iOS7 yesterday, since then messages between us are Text Messages only. We screwed around with everything. We discovered if i send to his email address (checkmarked with iMessage) it works. ALSO...after searching and trying different things, he can send me iMessages from his number, but when i respond it switches SMSs . FaceTime also works.
    It works with all my other contacts without issues.
    We both tried the following.
    - deleting eahcother as contacts,
    - resets (many)
    - turned off iMessage (reset network settings)
    - logging in and out of appleID in several locations
    - removed checkmarks from emails/phone number
    - on WiFi, on 3G
    - phone restore
    Start new conversation: only my phone # is checkmarked. receinve, I have 3 emails and phone number
    any ideas?

    Welcome to Apple Support Communities
    Open Finder, press Option key, select Go > Library, open Preferences and delete com.apple.imessage.bag.plist and com.apple.imservice.iMessage.plist

  • My Viewsonic monitor won't work with the Imac using the Mini Port to DVI adapter.

    My Viewsonic monitor won't work with the Imac using the Mini Port to DVI adapter. I also tried the HDMI to DVI adapter ane the Mac-Mini with same result. The monitor does work on my older Macbook Pro that has the DVI connector. Is it a Software/Driver issue ?

    Should be extremely simple, please carefully read Connect multiple displays to your Mac. If you still have problems then it's probably a cable issue that would be resolved by replacing the adapter cable. You should be using this adapter. If you are using a third party adapter that might be your problem!

  • New ipod touch won't work with itunes 10.6.3 says it needs 11.1 but I cannot load that on my macbook using OSX 10.5.8 any way around this?

    New ipod touch won't work with itunes 10.6.3, says it needs 11.1 or newer but I cannot load that onto my MacBook running on OSX 10.5.8 - is there anyway around this?

    No. If your MacBook has an Intel processor you can update to OSX 10.6.8 and then install the latest iTunes.
    A 5G iPod with iOS 7 requires that if you have a Mac you have OSX 10.6.8 or later.
    You can get 10.6.8 here:
    http://store.apple.com/us/product/MC573/mac-os-x-106-snow-leopard

  • TS1363 "An iPod has been detected but it could not be identified properly"  iPod Nano 7g and 3g won't work with Windows 8 PC. worked fine up until a month or so ago and now they are not recognized.

    "An iPod has been detected but it could not be identified properly"  iPod Nano 7g and 3g won't work with Windows 8 PC. worked fine up until a month or so ago and now they are not recognized.

    Hi cueball819,
    Thanks for using Apple Support Communities.  This article has steps to try if your iPods aren't recognized by iTunes or Windows:
    iPod not recognized in My Computer and in iTunes for Windows
    http://support.apple.com/kb/TS1369
    Cheers,
    - Ari

  • Itunes updated and now it won't work.  I unstalled it and reinstalled the older version and it still won't open. Says the itunes library won't work with the older program. Help

    Itunes updated and now it won't work.  I unstalled it and reinstalled the older version and reinstalled a older version and it still won't open.  Says the itunes
    library won't work with the older program.  Please help

    It says it cannot removed the older version of iTunes.
    Doublechecking before proceeding ... what's the precise text of that message, please? (There's a couple of different ones I can think of that you might be getting.)

  • I would like to update to Firefox 5.0.1, but I can't due to, too many things won't work with the version & will be disabled.

    I have wanted to update from 3.6.22, to 5.0.1, but can't do to the following reasons: I can't due to, too many things won't work with the version & will be disabled. They are: Microsoft. NET Framework Assistant 1.2.1, Iconix 3.90.1, HP Detect 1.0.5.1, Yahoo! Toolbar 2.3.5.201101200332202 (I don't care about Yahoo! Toolbar, because I don't use it!). As soon as these issues are fixed, I will be able to update, to the latest versions. These issues should be fixed & ready to work, before a new version is available. Thank you!

    Try using this extension to force compatibility.
    * https://addons.mozilla.org/en-US/firefox/addon/add-on-compatibility-reporter/
    Check and tell if its working.

  • I have a Canon D60 camera, my raw files won't work with the raw converter in my Photoshop CS5. Do I need CS6?

    Photoshop CS5 won't work with the raw files from my new Canon D60 camera. Do I need CS6?

    A Canon EOS D60? It had support since Camera Raw version 1.0.

  • FM transmitter won't work with my iPhone

    I bought a Premier FM transmitter from Auto Zone the other day. It has a 30-pin connector with an led panel that lights up when you connect it to an apple device. It's suppose to work with all 30-pin devices but doesn't work with my iPhone 4 (iOS 7.1.2). I have tried it with my iPod Touch 2g and two other iPhone 4's that belonged to my friends, and it worked with all three devices. Any explanation why it won't work with mine?

    "the Middle East" is a really big place. I suspect you bought a gray market hacked phone. Call Apple Care and give them the serial number. Maybe they can tell you if it's locked and to what carrier.

Maybe you are looking for