Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

KeyListener working randomly

 
Nikos Stavros
Ranch Hand
Posts: 243
Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a program that the key listeners only work at random. When I start the program they work sometimes, and sometimes they dont work.

my code is as follows
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if it is working randomly, something might be stealing the focus

try adding a focusListener, and in focusLost print a message to indicate that
is the problem.

or, if you are holding down the key, per your last thread, do you have it coded
so the keyEvent is not continuously firing?
 
Nikos Stavros
Ranch Hand
Posts: 243
Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try adding a focusListener, and in focusLost print a message to indicate that
is the problem.


When the paddles are working I get correct messages with this code

however when I have the problem when I toggle between the game windows and other windows I get not print out statements

so the keyEvent is not continuously firing

I'm not sure how to do this because I would have thought that as long as the key is down KeyEvents would be fired continously
[ November 06, 2006: Message edited by: Nikos Katsikanis ]
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> I'm not sure how to do this because I would have thought that as long as the
> key is down KeyEvents would be fired continously

keyEvents are forwarded to the current focus owner, otherwise you have a simple keyLogger.

if you want something to keep working whilst unfocused, use a timer
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic