Re: How can I get input using SDL without this strange edit box popping up
@keithwipf1:
Most games want to pay attention to both key down and key up events, as well as remember which keys are currently held.
Consider jumping in Super Mario Brothers or Donkey Kong Country.
When you press down the jump button, the code initiates your jump immediately.
It then increases your height until you either release the key, or reach the maximum height you are allowed to jump.
Then it reduces your height until you land.
If you only paid attention to the key up event for a jump, then you would not jump until you released the key, which would both feel laggy, and not allow you to adjust how high your jump is based on how long you hold the button.
Obviously you don't need behavior that advanced in a menu, but waiting for the key up event tends to add between 60 and 90ms of extra latency when I am trying to press and release the key quickly, and between 100 and 200ms when I am pressing keys in a more casual way as I would in a menu.
I can send a network packet from San Francisco to London in about 70ms, so wasting that much latency on waiting for a key up instead of a key down seems unnecessary.
Someone has a _javascript_ example that measures the time between your key down and key up events here, though it would be trivial to make your own more accessible test:
http://jsfiddle.net/jfriend00/AveZP/
It is not hard to ignore repeat key down events.
Both SDL and win32 provide information with the key down event that tells you whether it was a repeat key or not, so just check that value and ignore the repeat keys.
In addition, you usually want to remember which keys are currently held anyway, which would also allow you to know if a key down event is a repeat key by checking it against your array of held key states, just in case the input API were not telling you whether it was a repeat key.
There are some situations where waiting to perform the action until you receive a key up is the right choice.
For instance, the Humanware Victor Reader Stream waits for key up events before performing actions.
This is because some of the keys perform a secondary action if you hold them instead of just quick pressing them.
Obviously you can only determine if a user is going to quick press or hold for multiple seconds by waiting until the key up fires or a certain amount of time passes after receiving the key down event without receiving the key up event.
In this case, the key down event is still important because it marks the start time.
Players may appreciate key repeat in very large menus, such as an inventory with no limit to the number of items it can hold.
I definitely had complaints when I accidentally disabled key repeat in Tactical Battle grids, as people would use it to move their review cursor across the map quickly.
You can also support page down and page up keys, or control arrow keys to jump by larger amounts as an alternative to key repeat.
If you actually want to use key repeat, but do not want players to configure it in windows themselves, you can always simulate key repeats within your game by recording the timestamp when a key was first held, then triggering repeats at certain intervals.
Bokurano Daibouken 3 and ShadowRine seem to do something like this with their tile camera / field viewers.
You could do something similar for a pistol that you have fire again after a cooldown time.
For something with constant fire like a machine gun or flame thrower I would just pay attention to the fact that the key is held and deal a small amount of damage on every frame, keeping a constant fire sound looping seamlessly.
Also worth realizing that double click or double tap actions either require you to always wait long enough to detect the second tap, or ensure the single click action is impotent or naturally extended by the double click action.
An example of the latter would be how single clicking the mouse on an icon in windows selects that item, and double clicking activates it.
It makes sense that activating an item would also select it, so having the single click perform the first part of that sequence is fine and can be responded to immediately.
Fighter style games such as the Street Fighter, Mortal Kombat, or Killer Instinct series actually incorporate initiating animation sequences for actions and then aborting those if you follow them up quickly enough with additional key presses that change the initial action into a combo / special move.
They also keep a history of key down and key up events with timestamps so they can detect those combos that are a sequence of key presses.
Hope some of this information is helpful.
-- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector