• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

Capturing Key Presses

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. In java is there any way to capture what key a user pressed, even when the application is minimized? (I couldn't get KeyListener to do this)

2. How can I make java block a certain key from being pressed? For example, I want to replace a key with another. If I could block 'e' from doing anything, then I could use the robot class to make it do what I want.

The reason I want to do this is a little complicated. If you care for an expanation, please ask, but otherwise, it's irrelivent (no, I am not trying to screw up someone's computer).

P.S. I am nice! This thread is nice! I am being nice!
 
Rancher
Posts: 43045
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java will only see key strokes if it's the application in front. You could probably use JNI to tap into the native OS key handling code directly - that might enable you to read all key strokes.

As to the 2nd question, can't you simply ignore those key strokes? Check for them in your handler and don't do anything about them? Maybe I'm misunderstanding what you're trying to do, because I don't know where the Robot class would fit in.
 
Sean Smithway
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to make it so when I press the e key key in another application for example it will actaully press the t key.
 
author and iconoclast
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's really too low-level and platform-dependent for Java. If this is on Windows, use a Microsoft language and program directly to the Win32 (or .NET) API. Otherwise, use what's appropriate to that platform. You're not going to be able to do this in Java.
 
Sean Smithway
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you, but what about simple shortcuts. For instance, I might want ctrl-m to focus the java application, even when another unrealated application is opened.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic