Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. KeyListener - keyPressed delay

KeyListener - keyPressed delay

Scheduled Pinned Locked Moved Java
questiongame-dev
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    max29297
    wrote on last edited by
    #1

    Hey guys! Just a quick question... So I've added a KeyListener to my JPanel for a game I'm making, and everything is working out fine, except for one thing: When I hold down a key, keyPressed is called once, followed by a delay, followed by several consecutive calls of the keyPressed method. I understand that this has to do with the way key events are processed and that you can adjust this delay within the control panel, but is there any way to remove this delay completely? I'm thinking what I'm going to end up doing is creating a boolean keyDown variable which is set to true on keyPressed and to false on keyReleased. Any other ideas? :)

    M 1 Reply Last reply
    0
    • M max29297

      Hey guys! Just a quick question... So I've added a KeyListener to my JPanel for a game I'm making, and everything is working out fine, except for one thing: When I hold down a key, keyPressed is called once, followed by a delay, followed by several consecutive calls of the keyPressed method. I understand that this has to do with the way key events are processed and that you can adjust this delay within the control panel, but is there any way to remove this delay completely? I'm thinking what I'm going to end up doing is creating a boolean keyDown variable which is set to true on keyPressed and to false on keyReleased. Any other ideas? :)

      M Offline
      M Offline
      max29297
      wrote on last edited by
      #2

      Well thanks for all of your wonderful help guys, but I just thought I'd let you know that I went ahead and used my idea with the booleans.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups