• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

KeyListener working randomly

 
Ranch Hand
Posts: 243
Python
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic