Catch KeyDown events for modifier keys

I need to be able to tell when a user presses or releases the CTRL key for my application, but I can't get KeyListeners to work and the key bindings only appear to work with releasing the key. I also have key bindings for CTRL key combinations (like CTRL-N, CTRL-S, etc.), but I need an event which is fired when the user first presses the CTRL key. The goal is to have a tooltip on my custom JPanel which pops up when I press CTRL and goes away when I release it.
My (broken) key binding code:
JPanel main=new JPanel();
InputMap im=main.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
im.put(KeyStroke.getKeyStroke("pressed CONTROL"), "cDown");
im.put(KeyStroke.getKeyStroke("released CONTROL"), "cUp");
main.getActionMap().put("cDown",new AbstractAction() {
    public void actionPerformed(ActionEvent e) {
        isCtrlDown=true;
        updateTooltip();
        System.out.println("down");
main.getActionMap().put("cUp",new AbstractAction() {
    public void actionPerformed(ActionEvent e) {
        isCtrlDown=false;
        updateTooltip();
        System.out.println("up");
});If you press the control key a few times over this component, you only get "up" printed.

Hi BaconOppenheim,
Could you let me know which locale/input source you're using? I've run through some tests with the configuration you mentioned and I'm not seeing a problem. There is an issue with Ctrl+Click as that triggers a right click on Mac but the Alt key is certainly working on mouse events.
Could you send a screen shot of the test extension output after running:
1. Click + Shift key down
2. Click + Alt key down
3. Click + Cmd key down
4. Click + Shift key + Alt key + Cmd key down
That should cover the cases and show me the exact results.
Thanks,
Greg

Similar Messages

  • Listening events for numeric keys

    Hi,
    How can I listen events for numeric keys without using Canvas?
    I mean I would like to take some actions when user writes something
    on a TextField. My main class is not inherited from Canvas and because of that
    I can't use keyPressed() method to handle these numeric keys.
    Is there a way to handle these events in commandAction() method?

    Hi,
    If u r concerned only about the texfields and if you are using MIDP 2.0 compatible device then try ItemCommandListener.

  • Flex 4 does not dispatch keyboard events for ENTER key.

    Hello everyone. I think I have a strange problem with Flex 4 Beta (4.0.0.8909). My application has had event listener for keyUp event for a month now and suddenly (two days ago) I've noticed that keyUp event is not dispatched for ENTER (ALT also) key. Anyone know why? By the way, I've tried this with keyDown event, also 4.0.0.8847 version of SDK - still the same: no keyboard events for ENTER (and ALT) key.
    Here is the sample application that has got this issue:
    <s:Application
       xmlns:fx="http://ns.adobe.com/mxml/2009"
       xmlns:s="library://ns.adobe.com/flex/spark"
       xmlns:mx="library://ns.adobe.com/flex/halo"
       minWidth="640" minHeight="480"
       keyUp="application1_keyUpHandler (event)">
       <fx:Script>
          <![CDATA[
             import mx.controls.Alert;
             protected function application1_keyUpHandler (event: KeyboardEvent):void
                Alert.show ("Key up: " + event.keyCode);
          ]]>
       </fx:Script>
       <s:layout>
          <s:BasicLayout/>
       </s:layout>
       <s:TextArea verticalCenter="0" horizontalCenter="0" width="200"/>
    </s:Application>
    If you run this application and try typing anything in a TextArea you will get alerts with key codes. However, if you press ENTER (or ALT), you will get no alert.
    I'm pretty sure the code above is right so that means there is a bug in latest nightly builds of SDK (i would swhitch to an older build if i knew which one does not have this bug).
    Any ideas?

    Flex harUI wrote:
    That's true, but in this case, I think the text editing code is eating ENTER key in order to prevent parents from seeing it and acting on it (like a submit button).  We'll see if we can find a way around that.
    You can get the ENTER key now by listening in capture phase.
    Alex Harui
    Flex SDK Developer
    Adobe Systems Inc.
    Blog: http://blogs.adobe.com/aharui
    The enter key isn't being disposed of by textedit, the attached example code works without error if you a- remove the alert box and b-set the focus to your text area on initialisation. I agree that pressing the enter key then calling a dialog box will result in the enter key being "gobbled up" as  the enter key is overridden by the dialog box code.
    I think the first suggestion should be to anyone don't use dialogboxes for testing code. If for some reason debugging isn't desirable instead of a trace statement a simple label  can be used as a 'fake' trace.
    David
    Message was edited by: David_F57: I worded this wrong, imho there is no need for a work around, the textarea component works as it should. When intercepting 'system' keycodes there is a need to consider the effect of the intercept and code appropriately to that end.

  • How to catch the event for change dropdown value in alv

    it has a column output by dropdown in alv. the dropdown type cl_salv_wd_uie_dropdown_by_idx.
    now the problem is if change the dropdown value, i want to catch the event to change another column value.
    how can i do it?

    This part contains other ALV initialization code
    *... init ColumnSettings
      DATA:
            lr_column_settings TYPE REF TO if_salv_wd_column_settings.
      lr_column_settings ?= wd_this->r_table.
      DATA:
            lt_columns TYPE salv_wd_t_column_ref.
      lt_columns = lr_column_settings->get_columns( ).
      DATA:
            ls_column     TYPE salv_wd_s_column_ref,
            lr_col_header TYPE REF TO cl_salv_wd_column_header,
            l_tooltip     TYPE string.
      LOOP AT lt_columns INTO ls_column.
        CASE ls_column-id.
          WHEN 'PLANETYPE'.
            DATA:
                  lr_drdn_by_key TYPE REF TO cl_salv_wd_uie_dropdown_by_key.
            CREATE OBJECT lr_drdn_by_key
              EXPORTING
                selected_key_fieldname = ls_column-id.
            lr_drdn_by_key->set_key_visible( abap_true ).
            ls_column-r_column->set_cell_editor( lr_drdn_by_key ).
          WHEN OTHERS.
        ENDCASE.
    ENDLOOP.
      DATA:
            node_info TYPE REF TO if_wd_context_node_info,
            lt_valueset   TYPE STANDARD TABLE OF wdr_context_attr_value,
            l_value       TYPE wdr_context_attr_value.
      node_info = wd_context->get_node_info( ).
      node_info = node_info->get_child_node( 'FLIGHT_INFO' ).
    data : lt_sflight type STANDARD TABLE OF sflight,
           ls_sflight like LINE OF lt_sflight.
    SELECT * from sflight into TABLE lt_sflight.
    LOOP at lt_sflight into ls_sflight.
      l_value-value = ls_sflight-planetype.
      l_value-text  = ls_sflight-planetype.
      INSERT l_value into TABLE lt_valueset.
      ENDLOOP.
      node_info->set_attribute_value_set(
      name = 'PLANETYPE'
      value_set = lt_valueset ).

  • Callback event for modified text file

    I am looking for a way to register, in LabVIEW, an event that signals when a text file has been changed by a 3rd party software. I could use the 'File/Directory Info' LV primitive in a loop to let me know when the file has been changed but that would be very inefficient. Does someone know of a COM object that would let me 'stream' the changes of the text file or that allowed me to register an ActiveX callback event?
    Chris_Mitchell
    Product Development Engineer
    Certified LabVIEW Architect

    Archimedes wrote:
    I am looking for a way to register, in LabVIEW, an event that signals when a text file has been changed by a 3rd party software. I could use the 'File/Directory Info' LV primitive in a loop to let me know when the file has been changed but that would be very inefficient. Does someone know of a COM object that would let me 'stream' the changes of the text file or that allowed me to register an ActiveX callback event?
    If you know C/C++ well, take a look Window API: FindFirstChangeNotification.
    You can find it doc on MSDN.
    George Zou
    http://gtoolbox.yeah.net
    George Zou
    http://webspace.webring.com/people/og/gtoolbox

  • How to create a keypress event for ANY key on the keyboard that is pressed ? (not a specific key.)

    I realise that if I use:
    if (e.which == 81) {
    do whatever
    I can activate an action based on key 81 being pressed.
    But how would I do the same, regardless of what key is pressed?

    Sorry, figured it out...
    I just don't need to specify an if..... at all.
    Duh!

  • Backspace not detected as KeyDown Event

    Hi
    I'm trying to determine if the back space is pressed on my WPF. And I'm getting no where!
    My code (which is the event handler for the KeyDown event for a textbox)
    private void CompanyName_KeyDown(object sender, KeyEventArgs e)
    MessageBox.Show(e.Key.ToString());
    If I press a number, return (enter), letter or even a function key (F2, F3 etc) it works. But, delete, backspace and spacebar do not cause the event to fire.
    Any idea why?
    Dave

    Hey DaveRook, I hope you're fine.
    I believe you may check the following approach:
    if (Keyboard.IsKeyDown(Key.Back)) //Also "Key.Delete" is available.
    //Your code goes here..
    Please, mark my reply as Answer if it helps or vote it up if it gives a key to the solution.
    Thanks in advance and good luck.
    Ahmed M. Gamil
    "It is not titles that honor men, but men that honor titles."

  • Best practice for responding to keyDown event

    I am writing my first Cocoa application.  It's a simple utility app -- a calculator.  I've got everything working, the last thing I want to add is I want the app to respond to key press events.  So, you could click the "4" button with the mouse, or you could just press the "4" key on the keyboard.  I'm reading all the event handling documentation, but I'm not picking up on the recommended approach for getting an NSResponder (or NSView) that handles the event.
    I can make a subclass of NSWindow and tell the interface builder to make the main window of that type.  Then when I override the keyDown message in my new NSWindow subclass, it gets the events, but I'm not sure how to connect it to my application delegate class (since I basically just want to switch on the key pressed and call the corresponding message in the delegate that the button "select" action targets.
    Or, I think I heard something about doing this by changing the super class of the application delegate class from NSObject to NSView, or NSResponder or something.  I haven't poked at that idea much, but I'm not sure how to actually get the application delegate object then actually set up as the first responder (I think that's what I'd want to do).
    So, I'm hoping someone can give me specific directions on how/where I should implement my keyDown method, but I'd also like to understand what the recommended "best practice" is for doing this.  What would Apple say is the right architecture for doing this?  I'm as much interested in learning how to make this work as learning the Apple design pattern behind it.
    The structure of my program is as follows:
    I have one nib file (actualy a .xib) where I've designed my window with a textbox for display and a hand-ful of buttons.  I've registered outlets and actions from there to the AppDelegate class (the one that the standard project template sets up for you).  Following the MVC pattern, I then have a Calculator class that the AppDelegate initializes and all the actual logic of the calculator is in that class.  The AppDelegate basically just responds to messages from the buttons, passes them along to methods in the Calculator class, and then asks the Calculator for the current display value and updates that back into the textbox. So, the graphical elements in my nib file are the "view", the AppDelegate is the "controler" and the Calculator class is the "model".  Right? 
    So, who is supposed to be handling keyDown events?   Seems like the view should capture them and send them to the controller, but how do I set that up?

    Dear Noppong,
    You can do it with multiple ways like :-
    1. Get the current host name and make complete URL with using host name for the webdynpro iview.
    request = (IPortalComponentRequest) this.getRequest();
    HttpServletRequest req = request.getServletRequest();
    StringBuffer strURL = req.getRequestURL();
    2. Create the KM Document or Link for webdynpro Iview OR Create the WPC Web Page for the webdynpro ivew
    Refer to [http://help.sap.com/saphelp_nw70/helpdata/en/06/4776399abf4b73945acb8fb4f41473/frameset.htm|http://help.sap.com/saphelp_nw70/helpdata/en/06/4776399abf4b73945acb8fb4f41473/frameset.htm]
    [http://help.sap.com/saphelp_nw70/helpdata/en/06/4776399abf4b73945acb8fb4f41473/frameset.htm|http://help.sap.com/saphelp_nw70/helpdata/en/06/4776399abf4b73945acb8fb4f41473/frameset.htm]
    [http://help.sap.com/saphelp_nw70ehp1/helpdata/en/ff/681a4138a147cbabc3c76bde4dcdbd/content.htm|http://help.sap.com/saphelp_nw70ehp1/helpdata/en/ff/681a4138a147cbabc3c76bde4dcdbd/content.htm]
    Hope it will helps
    Best Regards
    Arun Jaiswal

  • Arrow key in the keydown event

    Hello,
    I used the keydown event to display the characters on the Screen depending on the key which is pressed,
    but if I press arrow keys and want to display "x" on the extreme right side of the characters for example :
    abcsdex
    here x is displayed when left arrow key is pressed. I tried it but x is not displayed where I want it is displayed on the extreme left of the characters or in between the characters.
    Thank you.

    I used the keydown event to display the characters on
    the Screen depending on the key which is pressed,
    but if I press arrow keys and want to display "x" on
    the extreme right side of the characters for example
    abcsdex
    here x is displayed when left arrow key is
    pressed. I tried it but x is not displayed where
    I want it is displayed on the extreme left of the
    characters or in between the characters.
    Thank you.write a KeyPressed event.get a ASCII value of the key you want to press.Then append the ASCII value of that pressed key to the current string in your desired position.First store the current string to a String variable.

  • Detect key or modifier key when in MouseUp event of a button?

    Is there any chance to accomplish this? When I app.alert the "keystroke" or "modifiers" property, it always returns false. Any chance to detect if and probably even which (modifier) key was pressed when clicking the button?

    To detect shift, use event.shift. See the documentation for more information: http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.604.html
    There's no way to know what other keys are pressed when a button is clicked.

  • How to handle form close event or escape key press event for user defined f

    Experts,
    Please let me know how to handle form close event or escape key press event for user defined form...
    Thanks & Regards,
    Pravin.

    Hi
    You can catch the form close event like this
    If ((pVal.FormType = 139 And (pVal.EventType = SAPbouiCOM.BoEventTypes.et_FORM_CLOSE)) And (pVal.Before_Action = True)) Then
          Try
                   SBO_Application.SetStatusBarMessage(pVal.EventType.ToString())
          Catch ex As Exception
                    SBO_Application.SetStatusBarMessage(ex.Message)
            End Try
          End If
    Hope this helps
    Regards
    Arun

  • Regarding access key for modify predifined fm in SAP IDES System

    hai to all,
    How can i find
    access key for modify predifined fm in SAP IDES System
    i have sap 4.7 dump(IDES)
    please give reply asap.
    thanks in advance,
    regards,
    surya.

    Hi Chandran,
    Thank you for the reply,
    how can i access this site, its asking username password,
    i didn't have both of these and even i'm unable to register also.
    how can i access.
    please respond
    regards,
    surya.

  • Getting the keyboard modifiers key state before injecting event.

    I'm using the Robot to inject keyboard events into a host computer from multiple clients.
    Since each client can have different modifiers keys (i.e. Shift, Alt, Ctrl, ...) set at a time and
    clients can interrupt each other, I need to be able to read from the host computer what
    modifier keys are set at that moment to get things back into synch.
    The KeyEvent class has a way to get the modifier keys through:
    KeyEvent.isShiftDown();
    KeyEvent.isControlDown():
    But this doesn't help (apparently) because that information is only available to a
    Keyboard listener when a key is pressed.
    What I need is a way to "get" the current keyboard modifier keys state before injecting
    an event through the Robot.
    Would anyone know how to do this?

    So... the clients send input events to the host and the host in turn simulates those events with the use of a Robot. Is that correct?
    If so then the program needs to save the last injected keyboard input that had a modifier mask in a field somewhere. Whenever you need to ask if any modifier keys are being pressed, you need only to look at this field and see if it is a pressed event. However, this method won't be able to detect a person physically at the host computer typing stuff.
    The central problem is that you can query keyboard input from OS (such as asking if shift is currently pressed) without a focused window using the standard api. But a focused window kind of defeats the purpose of what you are trying to do.

  • How to make modifier keys lockable? (like Caps Lock for Ctrl or Alt)

    Playing around with the non-modal text editor ne, I found myself wondering if one could simulate a modal interface (like vim has) by having something like "Ctrl Lock" or "Alt Lock" (analogous to Caps Lock) and thus a "ctrl mode"/"alt mode". I would like to try this, but I am not sure how to make it happen.
    My best guess is that this could be accomplished via XKB, but its documentation looks pretty intimidating. Is anyone here proficient in XKB and could point me in the right direction?
    Other ideas:
    – Is this something that a terminal emulator could do? Is there already one that can do it?
    – Or a shell?
    – For console applications, would it be possible to have a small wrapper that did nothing but intercept keyboard input and just pass everything through to the wrapped process, except that it would take into account the desired lockable modifier key? (I am thinking of tput here, but from my first search it appears that it doesn't do this sort of thing.)

    @Trilby: Thank you for the elaborate input!
    @drcouzelis: "sticky keys" normally means that modifiers remain active only until the next keypress, while I want a way to lock them in active state for an arbitrary number of keypresses. But still, "sticky keys" was a worthwile input for the search engine.
    The program xkbset, which can be used to set XKB options on the fly, has a function that comes very close to what I desire:
    $ xkbset h
    Usage: To set or unset various options:
    xkbset <options>
    where <options> may be all or any of (the '-' switches the feature off,
    otherwise it is switched on):
    To switch sticky keys on or off, and optionally set or reset:
    () two keys pressed at the same time stops sticky keys;
    () a modifier pressed twice will be locked:
    [-]{sticky|st} [[-]twokey|[-]latchlock]...
    I cannot select specific modiers to be affected with xkbset, but that would be fine with me. Sadly, it didn't completely work for me:
    – It doesn't affect Alt at all for me.
    – The effect seems to go away as soon as I change the window. (Maybe I need to invoke xkbset from .xinitrc for its effects to persist throughout the session? I will try that.)
    So I went on and tried to configure XKB manually. I got up to a certain point without studying the documentation in-depth, but now I have landed on an error message that seems to suggest to me that I would have to get to a better understanding about the layout files before I could understand it. Here is what I did:
    1. Got my current XKB configuration:
    xkbcomp :0 output.xkb
    2. Editet output.xkb to include the following at the end of the xkb_compatibility section:
    //Hoping this makes the ^-key into a Ctrl-Lock key:
    interpret TLDE {
    action= LockMods(modifiers=Control);
    3. Then I recompiled the configuration back into the running X server:
    $ xkbcomp out.xkb :0
    Warning: Compat map for group 2 redefined
    Using new definition
    Warning: Compat map for group 3 redefined
    Using new definition
    Warning: Compat map for group 4 redefined
    Using new definition
    Error: Couldn't lookup keysym
    Symbol interpretation ignored
    Warning: No symbols defined for <AB11> (keycode 97)
    Warning: No symbols defined for <JPCM> (keycode 103)
    Warning: No symbols defined for <I120> (keycode 120)
    Warning: No symbols defined for <AE13> (keycode 132)
    Warning: No symbols defined for <I149> (keycode 149)
    Warning: No symbols defined for <I154> (keycode 154)
    Warning: No symbols defined for <I168> (keycode 168)
    Warning: No symbols defined for <I178> (keycode 178)
    Warning: No symbols defined for <I183> (keycode 183)
    Warning: No symbols defined for <I184> (keycode 184)
    Warning: No symbols defined for <FK19> (keycode 197)
    Warning: No symbols defined for <FK24> (keycode 202)
    Warning: No symbols defined for <I217> (keycode 217)
    Warning: No symbols defined for <I219> (keycode 219)
    Warning: No symbols defined for <I221> (keycode 221)
    Warning: No symbols defined for <I222> (keycode 222)
    Warning: No symbols defined for <I230> (keycode 230)
    Warning: No symbols defined for <I247> (keycode 247)
    Warning: No symbols defined for <I248> (keycode 248)
    Warning: No symbols defined for <I249> (keycode 249)
    Warning: No symbols defined for <I250> (keycode 250)
    Warning: No symbols defined for <I251> (keycode 251)
    Warning: No symbols defined for <I252> (keycode 252)
    Warning: No symbols defined for <I253> (keycode 253)
    The "Error" part is where I am currently stuck. It tells me that my changes were ignored (I no that it's about them because it goes away when I comment them out), but I don't yet understand why.

  • Feature Suggestion for Keyboard System Preferences - Modifier Keys

    I recently picked up an iMac and it came with the new low-profile aluminum small keyboard -- without the keypad.
    I really like the small keyboard except for one thing -- the placement of the fn and control keys. The larger keyboard has three modifier keys on the left side: Control, Option, Command. The small keyboard has four: fn, Control, Option, Command.
    It is annoying to switch between keyboards where the control key is in a different spot on each one. Retraining my finger on a per-keyboard basis is hard.
    Apple thoughtfully provided in System Preferences a Keyboard control panel and it thoughtfully provided a "Modifier Keys..." popup to allow you to reassign the modifer keys. A great feature.
    The problem is: you can't use this to modify the behavior of the 'fn' key. It is apparently hardcoded.
    If I could use the modifier keys dialog to change the 'fn' into a 'Control', then I could use this keyboard without swearing everytime I miss the control key.
    Another feature that would be great would be if I could also have different bindings for the modifers on the left side versus the modifiers on the right. That would allow me to reassign one of the right side modifier keys (that I never use) to be an 'fn' key.

    I'm in the exact same boat as you...that Fn key is driving me nuts. I tried DoubleCommand and some other things as well, but the only thing that's coming close to what I want is a free download called "KeyRemap4MacBook."
    Just go under the "Remap Fn Key" section and you can basically have it act as the Command key. (I actually always had my Command and Control keys swapped, so now both the Fn and Control keys now essentially act as the Command key.)
    There are a few quirks I haven't figured out -- I can't seem to do Forward Delete -- but again, it's the only thing I've found so far that works.

Maybe you are looking for