Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7690011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:17:57+00:00 2026-05-31T20:17:57+00:00

I found the method addAWTKeyListener in the class Toolkit, but I can’t get it

  • 0

I found the method addAWTKeyListener in the class Toolkit, but I can’t get it to work properly, whether or not the window has focus. My code is as follows:

import java.awt.AWTEvent;
import java.awt.Toolkit;
import java.awt.event.AWTEventListener;
import java.awt.event.KeyEvent;


public class KeyTest {

    public static void main(String[] args){
    Thread t = new Thread(){
        @Override
        public void run() {
        System.out.println("STARTING");
        Toolkit kit = Toolkit.getDefaultToolkit();
        kit.addAWTEventListener(new AWTEventListener(){

            @Override
            public void eventDispatched(AWTEvent event) {
            System.out.println("EVENT");
            if(event instanceof KeyEvent){
                KeyEvent kEvent = (KeyEvent) event;
                System.out.println(kEvent.getKeyCode());
            }
            }

        }, AWTEvent.KEY_EVENT_MASK);
        while(true);
        }
    };
    t.start();
    }

}

Is there something I’m doing wrong? I get to the point that STARTING prints and there are no errors. The even is simply not called.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T20:17:59+00:00Added an answer on May 31, 2026 at 8:17 pm

    I may be wrong as I’m certainly not an expert, but as far as I know what you’re trying to do isn’t possible in Java.

    Are you trying to capture a key click using a Java program, but without creating a window? Part of Java’s security, and this is what I may be wrong on, is that it can only listen to events inside Java windows created by that particular Java program.

    So if you were trying to make something key-logger-esque that runs in the background and captured a key press, it wouldn’t be able to do that.

    I wish I could give you a more concrete answer but I hope this helped.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found storeHtmlSource method description in Selenium reference , but can't figure out how
Can i change url(set parameter) without submit? I found this method http://google-web-toolkit.googlecode.com/svn/javadoc/2.1/com/google/gwt/user/client/Window.Location.html#replace%28java.lang.String%29 but it
Has anyone found a good method of mocking out ADO.Net Data Service calls from
I am getting a Method not found: 'Boolean MyCompany.LibraryAssembly.SomeFunction(System.String)' exception/error when running a VB.NET
I found this page describing the Muenchian method, but I think I'm applying it
Found this method of having DIV as custom google maps infoWindow. It works, but
To get a handle on a Java instance method which we can invoke later
I've been trying for hours to get my drawing method to work by drawing
In class: \\\android 1.5 source\frameworks\base\services\java\com\android\server\HardwareService I have found method that looks like would help
I found a method on the internet that can retrieve the Id of a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.