Responding to keyboard events when focus is lost

Is there any way to have a Java Application respond to keyboard events if the focus has been lost?

Media programs respond to keyboard events to turn up
the volume, etc... and the program does not have to
have the focus to do this.On the computer I'm using here, the keyboard button
to raise/lower the volume goes to the OS's volume control.
Not to an arbitrary application.
So the situation in your analogy is not mandatory.
And more generally, even if your app is not hidden,
users do not expect that it will "steal" keystrokes.
Let's say I download a very cool "World Clock Display"
program that displays the world time of New York
and Tokyo in the background.
Let's say I then go to my bank's website.
I do not want that the World Clock Program
(which is in full view) to capture my bank password.
(Clarification: on Windows, on Linux... it is
actually perfectly trivial for a C/C++ program
to capture all keystrokes in the background.
But I do not know if you can do it using Java or not)

Similar Messages

  • Itunes responding to keyboard controls when in background

    So, this is really irritating, and makes iTunes unusable. Even when minimized or the window is closed, iTunes is starting and stopping playback every time I hit the spacebar, and responds to the arrow keys skipping ahead or back.
    I've tried deleting the plist, re-installing iTunes, fixing permissions.
    This happened right after I upgraded to Leopard.
    Help!

    I was having the same problem, as well as a few other problems with iTunes. I fixed it, though, by closing iTunes and then deleting the ~/Library/Preferences/com.apple.iTunes.plist file. When iTunes opens again it will ask you a few questions... do you want to re-import songs, etc. Just say no; everything is still in there. And now it works fine for me.
    Note that a few of your preferences may be lost when you delete this file, but you shouldn't lose anything permanent.

  • FocusLost of jtable is not triggered when focus is lost from a cell editor.

    Hi
    I have a jtable and some columns in the table contains editable cells. I started editing a cell and, before the cell editing is stopped, i clicked another component in the panel using mouse. At that time, the focusLost() method of the table is not triggered. So that the code written in my focusLost() method of table is not working.
    If I add focuslistener to the cell editors, the focusLost() method of this cell editors are triggered at that time.
    Shall I need to add focuslistener to each cell editors used in my jtable ? Anybody know a better solution to handle this problem ?
    Regards
    Anoop

    Add this to your code.
    yourTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);

  • DATAGRID FOCUS ISSUE: Focus got lost, while moving from one cell to another cell using tab key.

    Problem: Focus got lost, while moving from one cell to another cell using tab key.
    Example: In an AdvanceDataGrid, there are three columns having custom ItemRenderer with Spark TextInput control (editable=true & focusEnabled=true).
    When I try to move the focus in with in 2nd, 3rd & 4th column using tab key, focus got lost. Most of the time it’s working, but some time it doesn’t work. There’s no clue as to how may rows/columns the focus has jumped to; or whether the focus has gone out of the data grid altogether.
    Observations: I am not sure whether this problem is because of custom component implementation or it is because of some issue related to Flex Component.
    It only occurs when we perform some actions like some server call, some complex logic execution etc. at the focus out event of itemrenderer.
    There is one property of datagrid i.e. editedItemPosition which contains row & column index of datagrid. On the focus out event, it gets null when focus got lost. We tried to set it, but it didn’t work.
    Steps Performed:-
    1. Currently focus is in 2nd column i.e. Apply to #.
    2. Once I press tab key from 2nd column, it goes to 3rd column which is correct.
    3. Now if I press tab key from 2nd column i.e. Payment #, focus should go to 3rd column, but it goes out of data grid and set the focus of button which is outside data grid.

    http://search.java.sun.com/search/java/index.jsp?qp=&nh=10&qt=%2Bjtable+%2Btab+%2B%22enter+key%22&col=javaforums

  • Detecting keyboard events outside the application

    is it possible to click a key when the air app is out of focus, and will trigger an event in air?

    You may want to check the security documentation on that one.  I don't know of many non-OS apps that can intercept keyboard events without focus.  Keystroke sniffers on the other hand ....

  • How to receive a keyboard event (arrowkeys)

    Hi,
    I'm a bit confused about how to setup event-handling for keyboard event. I have created a window with a File's Owner called "MyDocument". But if I implement the method
    <pre>
    -(void)sendEvent: (NSEvent *)theEvent {
    printf("Called\n");
    </pre>
    it wont be called. Does anyone know what else I have to do in order to receive keyboard events when a user presses an arrowkey inside my application ?
    Macbook Pro 15''   Mac OS X (10.4.8)   2GHz, 2GB

    You most likely need to implement -(void)keyDown:(NSEvent *)event to catch keyboard events and then query event for the key pressed. This method is defined in NSResponder together with mouseDown:, mouseDragged, keyUp:, etc.
    Here's a couple of examples from two sample apps:
    'Dicey' (online sample code):
    <pre>
    -(void)keyDown:(NSEvent *)event {
    // If the space bar was pressed, toggle hold on the first responder
    if ([[event characters] isEqualToString:@" "]) {
    [[dice objectAtIndex:firstResponderIndex] toggleHold];
    [self setNeedsDisplay:YES];
    } else {
    // We do care about our superclass dealing with tab shift-tab for first responder changes
    [super keyDown: event];
    </pre>
    'Worm' (From: /Developer/Examples/AppKit/Worm):
    <pre>
    - (void)keyDown:(NSEvent *)event {
    NSString *keys = [event charactersIgnoringModifiers];
    wormHeading = kGameHeadingStraight;
    if (keys && [keys length] > 0) {
    unichar c = [keys characterAtIndex:0];
    if (c == NSLeftArrowFunctionKey) {
    wormHeading = kGameHeadingLeft;
    } else if (c == NSRightArrowFunctionKey) {
    wormHeading = kGameHeadingRight;
    </pre>
    Note the use of NSLeftArrowFunctionKey for example in Worm. These and many other 'special' key constants are defined in NSEvent.

  • Detect mouse clicks or keyboard events on desktop or everywhere

    Hi,
    What I have to do is to start the application minimized in the system tray. Then the application must be listening for crtl+shift+left mouse click in any part of the desktop or an opened application, when that happens, I have to show a window asking if the user want to take a screenshot starting in the x,y point he clicked and then take the screenshot.
    What I don't know how to do is to detect the mouse and keyboard events when the application is supposed to be running minimized in the system tray.
    How can I do that? Can anybody give me a hint?
    Thanks in advance.

    It's not possible with plain Java. You will need native code for this. Take a look at JNA.

  • Capture All Mouse and Keyboard events even if java window NOT in FOCUS

    Hi All,
    Is this possible to capture all mouse and keyboard events even if java window is not in focus or is minimized. This java program should cature each and every event from the user once the program is started. Any help in this regard is appreciated!
    Thanks&Regards
    Sam

    I don't think you can. (without JNI)

  • Reset the time when he is typing(keyboard event) any info in from.

    Hi All,
    We have implemented auto session logout(if user is ideal for 15 mins one message popup will come and after 5mins user gets  logged off) in our portal and it is working fine. when user navigate to other page the timer is getting reset  but if user working in same page for 15 mins popup message comes and if is not clicking 'ok'user gets logged off .
    For navigation i am using EPCM.subscribeEvent("urn:com.sapportals:navigation", "Navigate", pop);
    My requirement is to reset the time when he is typing(keyboard event) any info in from.
    Please provide your inputs.
    Thanks,
    Santosh.

    Dear Santosh
    Regarding events between WD and Portal you need to consider the interface
    IF_WD_PORTAL_INTEGRATION
    Please check this to see how it is done
    http://wiki.sdn.sap.com/wiki/display/Community/Usingportaleventtocommunicatemultipledatabetweendifferentwebapplication%28WDAandBSP%29
    Kind Regards
    /Ricardo Quintas

  • Fire an event when loosing focus on "dateFrom" EditText

    Hello,
    im trying to fire an event when im "going out" dateFrom (EditText). I used the following code which is not working. Have You and different way to do it ??
    im main goal is to format the text in the EditText to the propriet one when the user will focus on other element.
    If pVal.EventType = BoEventTypes.et_LOST_FOCUS Then
    If pVal.ItemUID = "dateFrom" Then
    oAppObj.MessageBox("", 1, "OK")
    End If
    End If
    Thanks

    Hi Adele
    when im "going out" nothing happend. Im using this event  in my oAppObj_ItemEvent Sub,maybe here is my mistake ?? but i dont think so !!
    One more think:
    Im trying to work on the Employee Info and when i update some fields ( exp. startDate = 09/09/06  - dd/mm/yy) im getting an error ( the starting date is befor the birth date =21/01/70 dd-mm-yy) !!! is it a 2K year problem ??
    All this it looks so strange ... im using B1 2004A and VB.Net

  • Qt in AI Panel on MAC: Keyboard events/focus issue

    My plugin has panels that use Qt for UI, runs fine on windows. But on mac (qt embedded in panel using QMacNativeWidget) , QLineEdit and other components do not seem to receive focus, nor are processing keyboard events. I cannot type into the text boxes or navigate through tree widget.
    From Qt forums, seems like it is a known issue. Has anybody faced this issue, found a solution for this?
    Qt: 4.8.6
    OS: Mac os maveric
    Illustrator: CC

    There is a crude workaround that seems to work for me.
    I subclass QLineEdit and override QWidget::macEvent for detecting mouse events. On a button press I activate
    the window and set the focus manually:
    #include <Carbon/Carbon.h>
    bool MyLineEdit::macEvent ( EventHandlerCallRef caller, EventRef event )
    if(GetEventClass(event) == kEventClassMouse) {
       if(GetEventKind(event) == kEventMouseDown) {
          activateWindow();
          setFocus(Qt::OtherFocusReason);
      return false;
    I admit that this is not a perfect solution, but at least it gives you /some/ sort of usable behaviour.

  • Mouse/keyboard events lost during sound events

    I have a new MacbookPro (October 2011, MacBookPro8,2) with 4Gb RAM running latest 10.6.8, and I am extremely frustrated by periodic loss of mouse events (movement freezes, then jumps) and keyboard events (loss of keystrokes) whenever a sound alert is made. Am I the only person experiencing this?

    I should also add a related behavior, repeated keypresses. I do a lot of work on connected unix/linux machines using terminal. Sometimes I will be navigating directories and hit <tab> for command completion, and unexpectedly get the screen scrolling as if I had typed it 100 times!

  • Getting keyboard events with Group

    Hi all,
    I'm new to JavaFX and I'm trying to handle keyboard events in a group but it doesn't seem to respond when I press the keyboard.
    As I understand this is because Group doesn't receive the focus. If that is the case, how can I make it receive focus? I tried calling setFocusTraversable(true) and setFocused(true) but both haven't helped.
    If it's not the focus, what is it?
    Thanks!

    Use requestFocus() instead of  setFocused(true).
    Keyboards events work as expected  with a group.
    @Override
        public void start(Stage primaryStage) {
            Button btn = new Button();
            btn.setText("Say 'Hello World'");
            Group root = new Group();
            root.addEventFilter(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() {
                public void handle(KeyEvent event) {
                    System.out.println(event.getCode());
                    event.consume();
            root.getChildren().add(btn);
            Scene scene = new Scene(root, 300, 250);
            primaryStage.setTitle("Hello World!");
            primaryStage.setScene(scene);
            primaryStage.show();
            root.requestFocus();

  • 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.

  • CS2: Listbox and keyboard events

    Hello all,
    I have a listbox widget in a Palette, I need to catch keyboard events specifically I need to be notified when the user presses the RETURN key.
    I checked the PanelTreeView sample which defines a custom event handler but functions like KeyDown or KeyCmd are never called despite "CanHaveKeyFocus" has been modified to return kTrue.
    How can I be notified when user presses the RETURN key in the PanelTreeView listbox?
    Thanks in advance ...
    Jorge Martinez

    If the StageWebView has focus, you should be able to capture only the hardware key events (like BACK, ..). All the others are handled internally by StageWebView.
    Do you see otherwise? If yes, can you post your application ?
    Thanks,
    Raul

Maybe you are looking for

  • Work book taking longer time to open

    Hi, We created a workbook and embedded one  input ready query in it.  The query when executed separately takes 1 minute to load.  But when the work book is opened for the same selections, it takes 3-5 mins.  There is no Macros written in the workbook

  • HttpConnection hangs in my T630. Please Help !

    Hi all, I`ve noticed this problem in a few threads on this forum, but none of them seem to have a definitive answer. Maybe we can answer it once and for all here :-) Any help would be greatly appreciated. I`m trying to load a web page from a midlet i

  • Urgent Help WorkBench Tuxedo ART, Project BBVA Mexico

    Xin Cao, or who can support us. We are working on a draft Rehosting at BBVA Bancomer Mexico, along with Oracle Mexico through its representative (Javier Soto). We have studied and analyzed for Tuxedo Art WorkBench converter, but when trying to conver

  • Boot camp with usb media

    I have an .img file of Windows 7 that I downloaded from my university's software license. Disk Utility and Boot Camp assistant both failed to image my USB drive so I did it with terminal. However, when I go to install it, boot camp says that it can't

  • How to declare and use multi dimensional VARRAYs in PLSQL

    Hi All, I am trying to create and use multidimensional varray in plsql code... can anyone let me know, how can I do this... Thanks Krishna