Results 1 to 9 of 9

Thread: key listener

  1. #1
    nikkka is offline Member
    Join Date
    Mar 2011
    Posts
    45
    Rep Power
    0

    Default key listener

    i want to write a program that should run at the background and say what time is it, every time keys "1" and "2" are pressed. i found class keylistener which tracks keys, but because i want my program to run at the background, window is going to be inactive, so is going to be the component to whom i will add actionlistener. what can i do? :S

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    I don't know all the details, but perhaps you can just not set the frame to be visible, it will be running but you won't see it. You can have a frame pop up with the time when the correct key is pressed.

  3. #3
    nikkka is offline Member
    Join Date
    Mar 2011
    Posts
    45
    Rep Power
    0

    Default

    But, if window will be inactive it will not react on the pressed key :S

  4. #4
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Have you tried it? The window is active, it's just not visible, try it out and see what happens. Perhaps to test, just print to the console when some key is pressed.

  5. #5
    RichersooN is offline Senior Member
    Join Date
    Jan 2011
    Location
    Rizal Province, Philippiines
    Posts
    167
    Rep Power
    0

    Default

    #1. You can use add this to your constructor:
    Java Code:
    setAlwaysOnTop(true);

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default

    Can't be done in Java. An inactive window doesn't receive system events.

    db

  7. #7
    nikkka is offline Member
    Join Date
    Mar 2011
    Posts
    45
    Rep Power
    0

    Default

    And is there any way to activate the window by pressing combination of keys :S But, obviously, it's the same :X

  8. #8
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    @db, for my own personal knowledge, can an invisible frame receive key input? Normally I would try myself but I can't access a computer for about 4 hours.

    I'm wondering if it can listen for a certain key to be pressed, and when it fires the event can the listener open another window?

  9. #9
    nikkka is offline Member
    Join Date
    Mar 2011
    Posts
    45
    Rep Power
    0

    Default

    Well, theoretically, yes. I'll try that that out and post the result here.

Similar Threads

  1. GUI Listener not Listening
    By m_patten2 in forum AWT / Swing
    Replies: 2
    Last Post: 11-24-2010, 01:06 AM
  2. Action Listener
    By greatmajestics in forum AWT / Swing
    Replies: 8
    Last Post: 03-25-2010, 05:39 PM
  3. Tab Listener
    By teckno101 in forum AWT / Swing
    Replies: 2
    Last Post: 09-29-2009, 09:40 PM
  4. Regarding Listener
    By adeeb in forum AWT / Swing
    Replies: 2
    Last Post: 06-20-2008, 11:07 PM
  5. Regarding Listener
    By adeeb in forum AWT / Swing
    Replies: 2
    Last Post: 06-10-2008, 02:00 AM

Posting Permissions

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