10

Listen for scan codes. How this is done depends on your OS, which you did not list. On Windows, you can get the scancode for a given virtual key code from WM_KEYDOWN and friends by using MapVirtualKey. Scan codes are based on the physical key and are unaffected by layout. Have a quick read of http://www.altdevblogaday.com/2011/10/02/i-never-managed-to-go-...


10

An alternative way (Josh's approach is great too!) would be to setup an boolean on SDL_KEYDOWN, and possibly also ignoring all repeated key events. That you can do by checking the repeat member of the key event. Then you could implement your own timer, which doesn't have to be anything fancy, and implement key repetition your self. You could either trigger ...


9

Your problem is the fact that you're only looking at KEYDOWN events. What you need to do is toggle a boolean value when a key is pressed or released. Something like this would work: # event loop for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() elif event.type == pygame.KEYDOWN: # check for key ...


8

Firstly, you need to use a switch case statement and decide which direction overrides the others, for example, if they press all four buttons, which button should be listened to for input? This gets put in order within the switch statements. Edit: For clarity about the above statement. You do need to use a switch case statement (or similar structural logic) ...


6

Possible cause : From your code, no visible sources of lag are present. The lag may come from the way they are accessed from the game loop thread. Dont forget, the variables have to be synchronized, or you have to use locks for your app to be thread safe. The lag you experienced may be from the fact that you increment the x and y by 5 each. I am guessing ...


6

You should always give the player the ability to change their key assignments. That is how it is "usually handled": let the player change them. Some players will set their keyboard to QWERTY when they play games because that's what most games expect. Some will leave them set to their current keyboard and rely on the ability to change the keys.


6

In your keyPressed and keyReleased you can use a Map<Integer, GameInput> to map the KeyEvent.VK_* to GameInput Make a new enum with the actions you want to be controllable enum GameInput{ FORWARD, LEFT, RIGHT, BACK,PAUZE,... } And in Controller you have a Map<Integer, GameInput> that you use: public void keyPressed(KeyEvent e) { game....


6

To answer your first Question "why does the Engine behave like this" I would add the following: The Engine does not actually detect the key being pressed multiple times. What you need to keep in mind here is that the "was pressed" state of the key does not reset until the next frame, and your code will be executed in a single frame. Furthermore, every if ...


6

This is an excellent question because you are experiencing a problem that's quite commonplace with less experienced programmers: attempting to solve your problem with a purely imperative approach. Luckily this problem has been encountered and solved by people much smarter than I, thanks to the mathematical concept of a finite state machine. A finite state ...


5

You could use a library like KeyboardJS, which will listen the keyboard events and fill an array with the active keys. In your gameloop: var activeKeys = KeyboardJS.activeKeys(); if (activeKeys.indexOf(84) > -1) { // key pressed } I also made my own library, which is lighter but clearly less complete than KeyboardJS.


5

If, in your question, "twin-stick" is a misnomer and you just mean top-down shooter, that's different... My answer is going to assume you do mean "twin-stick." <sidenote>In the Binding of Isaac, only shooting in 4 directions was a specific design decision. (I can't find a source for that, but I recall Edmund saying it was intentional.) It's worth ...


5

This is pretty simple. Basically, you just have another key call the same function as U+K does. if((keyDown('U') && keyDown('K')) || keyDown('O')) doPowerBlock(); Basically that's saying if the U key AND the K key are pressed, OR the O key, do the action. Or depending on how you have things arranged, you could do something like: if((keyDown('U'...


5

Accordingly to http://legacy.lwjgl.org/javadoc/org/lwjgl/input/Keyboard.html you can make this like this: while (Keyboard.next()) { bool pressed = Keyboard.getEventKeyState(); int key = Keyboard.getEventKey(); if(pressed) processKeyPress(key); else processKeyRelease(key); } For more detail, you can google "Buffered input vs Unbuffered input"...


5

The best way to solve your concerns for flexibility and comfort of the user is to certainly allow them to define their bindings as you have described. Whether you opt to do this through a configuration file they manually edit or an in-game screen that allows them to select the action and then press the key configurations for said binding is entirely up to ...


5

Your issues does not seems to be "How do I accept only one directional input per update?" but rather "How do I prevent my snake to go backward?" From the many comments and discussion, you seem to be having a frame-rate that is not appropriate for the game you're developing. Traditionally, Snake is a game with a very low frame-rate, the snake moved only 2-3 ...


5

It is due to your flow is confusing for engine as it will try to execute your every check in every frame. Try to implement with else or with single statement like, using UnityEngine; using System.Collections; public class TestingKeyGetRecursion : MonoBehaviour { int counter = 1; void Update () { if (Input.GetKeyDown(KeyCode.F)) ...


5

Just as a heads up, most keyboards have a finite limit of keys that can be pressed. For example, I have an Asus Transformer Book and you can only press around ~5 keys at a time. Some keyboards also won't allow more than a few keys pressed if shift or control is being pressed. (Like my Transformer Book...) And yes, most of the time, this is hardware limited, ...


5

From your recapitulation this might be an key rollover problem. The term key rollover describes a tradeoff in keyboard design complexity for reduced production cost. Many standard keyboards have issues detecting more than three keys being pressed simultaneously. As you are using Swing, that means you are using java. So in order to find out if it is a ...


4

The program is trying to convert a unicode wide character format into a standard ascii format. The code you are trying to convert is out of the available ASCII format range. http://www.fileformat.info/info/unicode/char/444/index.htm This is the code you are trying to convert, and ASCII only supports 128 different values, with extended ASCII supporting 256. ...


4

SharpInputSystem was created for this exact purpose. It provides a portable way of access the Keyboard and Mouse on most platforms and GamePad/Joystick on a few others. In full disclosure, I am the author, but I needed a similar library for the samples I provide with Axiom. It may need to be modified to load the MonoGame assemblies properly, I am currently ...


4

I'm really sorry. I found the solution after ask the question by trying. As MarkR said, we need give focus on our canvas. Here is the pure javascript (without JQuery); canvasElm.setAttribute('tabindex','0'); canvasElm.focus();


4

I don't know python, but have you tried setting a bool to true when the key is pressed, and changing the speed in an if statement based on that bool. When the key gets released you just have to set the bool back to false.


4

Polling mechanism The software check for a condition repeated times until something is ready. E.g. Childs in a car: Child: Did we arrived yet? Mom: No; Child: Did we arrived yet? Mom: No; .... (repeat many times) Child: Did we arrived yet? Mom: Yes Events The condition itself is able to inform the software when it is ready. E.g. ...


4

Behind the scenes, typically input is polled anyway, just by the os behind your back ;) Regardless, even if you poll you're going to need to package state changes up in some way in order to use that information elsewhere in your game. And odds on you're going to package that up in an event. So realistically, going straight to events is going to save you ...


4

You may be dealing with keyboard ghosting, the phenomenon where certain keys cannot be pressed down simultaneously. This differs between different keyboards, but you can test it out in the link I've provided, which has an interactive program for testing key presses. You may be able to fix this problem by finding different keys that can be pressed together, ...


4

A summary Instead of mapping the input direcly to the action (and using enums will keep doing that because you would still have to map the key to the enums), you should make the input consume a method it holds. If it was an X-Box, for example, the X button can perfom an action defined by the player Use the inferface above to create something like bellow ...


4

Good news! This code: bool ctrl = Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl); already respects the user's OS settings for sticky keys and key remapping on Windows and macOS at least. And this works whether you specify the key by KeyCode, by a "Conventional Game Input" string, or by a remappable GetButton("Some Custom ...


Only top voted, non community-wiki answers of a minimum length are eligible