Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [SOLVED] Input handling: detect holding two keys  (Read 10999 times)

0 Members and 1 Guest are viewing this topic.

Hapax

  • Hero Member
  • *****
  • Posts: 3346
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Input handling: detect holding two keys
« Reply #15 on: October 09, 2014, 01:32:54 am »
If your system works as I read it, I wouldn't have thought that clocks would be necessary.
Assuming you're still using move.x and move.y, you could reset them both to zero before the checking and then add to it for each key. That way, if you press up and left, it become -1, -1, and if you press right and left together, x becomes zero.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Glocke

  • Sr. Member
  • ****
  • Posts: 289
  • Hobby Dev/GameDev
    • View Profile
Re: Input handling: detect holding two keys
« Reply #16 on: October 09, 2014, 04:39:35 pm »
If your system works as I read it, I wouldn't have thought that clocks would be necessary.
Assuming you're still using move.x and move.y, you could reset them both to zero before the checking and then add to it for each key. That way, if you press up and left, it become -1, -1, and if you press right and left together, x becomes zero.

Well, the problem is, that the system is faster at detecting key presses as the user could press. So the "seems to be simultanously" pressed keys for a diagonal move are not always detected as one action. Mapping keys to a movement vector is the right thing - but the system needs to detect both keys within the same frame as pressed.

Meanwhile, my input component is delaying some milliseconds (currently something between 70-100 I guess) after a single direction key was pressed. If the system recognizes another direction key (which isn't inverse to the previous) it modifies the movement vector and triggers the actual movement to the gameobject. Else (if no additional key occures within the next milliseconds, the previously generated vector (for the single key) is processed.
Current project: Racod's Lair - Rogue-inspired Coop Action RPG

Hapax

  • Hero Member
  • *****
  • Posts: 3346
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Input handling: detect holding two keys
« Reply #17 on: October 09, 2014, 08:36:41 pm »
Ah, I was incorrect. Don't reset each cycle. Instead just reverse the addition on a release (obviously, you've have to ignore any repeats).

If it starts off at (0, 0) at the beginning:
"Right" event is found; adds 1 to x: (1, 0).
"Up" event is found; subtracts 1 from y: (1, -1).
"Right release" event is found; subtracts 1 from x: (0, -1).
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Glocke

  • Sr. Member
  • ****
  • Posts: 289
  • Hobby Dev/GameDev
    • View Profile
Re: Input handling: detect holding two keys
« Reply #18 on: October 10, 2014, 09:18:00 am »
Ah, I was incorrect. Don't reset each cycle. Instead just reverse the addition on a release (obviously, you've have to ignore any repeats).

If it starts off at (0, 0) at the beginning:
"Right" event is found; adds 1 to x: (1, 0).
"Up" event is found; subtracts 1 from y: (1, -1).
"Right release" event is found; subtracts 1 from x: (0, -1).

 ;) That's the way :)
Current project: Racod's Lair - Rogue-inspired Coop Action RPG

 

anything