-
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
-
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.
-
But, if window will be inactive it will not react on the pressed key :S
-
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.
-
#1. You can use add this to your constructor:
Code:
setAlwaysOnTop(true);
-
Can't be done in Java. An inactive window doesn't receive system events.
db
-
And is there any way to activate the window by pressing combination of keys :S But, obviously, it's the same :X
-
@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?
-
Well, theoretically, yes. I'll try that that out and post the result here.