Results 1 to 2 of 2
  1. #1
    Addez is offline Senior Member
    Join Date
    Aug 2009
    Rep Power

    Default KeyBinding key released doesn't work so well -.-

    Hello again :D

    I would need help with keybindings..

    The keybinding works okej, I can get a method running when a key is pressed.
    But when I want keyreleased to trigger a method, it doesnt work..

    I watched oracles webbsite and many other for good examples but their
    examples aren't too explanitory on that area so I search for guidence here :P

    So, heres what I tried to do (first add normal key binding, then keyreleased binding):

    Java Code:
    private static void add(String keyPressA, int key, InputMap inMap,ActionMap actMap) {
            inMap.put(KeyStroke.getKeyStroke(key, 0), keyPressA);
            actMap.put(keyPressA, new ActionDone());
            keyPressA = "released "+keyPressA;
            inMap.put(KeyStroke.getKeyStroke("released "+key), keyPressA);
            actMap.put(keyPressA, new ActionReleased());
    Triggerd with the method call:
    Java Code:
    int condition = JComponent.WHEN_IN_FOCUSED_WINDOW;
            InputMap inMap = content.getInputMap(condition);
            ActionMap actMap = content.getActionMap();
    I get keypressed signals, but not keyreleased..
    How am I brutaly failing this time?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power


    You're doing it wrong. Look at the KeyStroke class's getKeyStroke method overloads. There's one that takes three parameters, an int, int and a boolean, and that should give you the key to all this. For an example of this, please have a look at this thread:


Similar Threads

  1. KeyBinding Help
    By Lil_Aziz1 in forum New To Java
    Replies: 12
    Last Post: 07-27-2010, 03:58 PM
  2. Replies: 1
    Last Post: 03-08-2010, 05:14 PM
  3. mouse Released no work!!
    By frenkelor in forum AWT / Swing
    Replies: 4
    Last Post: 01-23-2010, 05:49 PM
  4. Replies: 0
    Last Post: 01-05-2009, 11:48 PM
  5. ZombieEscape: Multiple KeyBinding at one moment?
    By Unome in forum Java Applets
    Replies: 0
    Last Post: 11-17-2008, 07:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts