Tag Info

Hot answers tagged

17

What you're trying to do is simple to solve without having to resort to doing any timing on the input (in fact I recommend you not to do so in this case - timing is more useful for scenarios such as limiting the firing rate of a spaceship). If you want for only the initial press of the key to be registered, the way it's usually done is: Keep track of ...


12

I'd say it's a good idea to set the hotkeys around the WASD area. At first it might be more intuitive to associate the command to its first letter, but it becomes a pain after you realize you have to push A and P 120 times a minute while handling mouse commands. With the hotkeys set from Q to R, A to F and Z to V, we have a series of advantages: You never ...


8

I've never been quite sure why people are so obsessed with numbers and the very edges of the keyboard. Tell the players to put their left hand on ESDF. Now map commands to the rectangle bounded by 1, 5, Z, B. That's space for twenty commands, over half of which of which are very easily accessible, most of the remainder being only moderately more difficult. ...


8

The best and simplest way to do it is to use your first idea and handle the WM_KEYUP/WM_KEYDOWN messages as well as the WM_SYSKEYUP/WM_SYSKEYDOWN messages. These can handle detecting the difference between left and right shift/control/alt keys, you just need the appropriate virtual key codes. They are VK_LSHIFT/VK_RSHIFT, VK_LCONTROL/VK_RCONTROL, and ...


7

If you set your interface up right, the association should be muscle memory, not the letter. I always like the keystrokes in Diablo II where each bar was just a row of keys, you didn't have to think about what the developer called something, just where you put it on your HUD. Perhaps the same approach could work in an RTS?


7

The code in your question is fine. The problem must be in the code above it, perhaps you are doing something like this: // ... if (ks.IsKeyDown(Keys.Down)) { /* ... */ } else if (ks.IsKeyDown(Keys.Down) && (ks.IsKeyDown(Keys.Left))) { /* ... */ } // ... In which case the first condition will trigger and the second will not (due to else). Here is ...


5

Use GetPressedKeys() to get all of the currently pressed keys and iterate through them doing what you want. If you're moving the player or something, create an initial Vector3 at the beginning and add modifier values to it and add it to the player position after the input checking has completed. Something like this: Vector3 positionToAdd = Vector3.Zero; ...


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

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 ...


5

Accordingly to http://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

You're taking the wrong approach with a static UI class. The usual way to "bounce" from a static callback to an instance function is to store something capable of making the jump in a place that is accessible from the static callback. Most APIs, like GLFW and native Win32, that require these sorts of static callbacks provide a way to make the association ...


4

What I'd do is use the observer pattern and have an input class that maintains a list of callbacks or input handling objects. Other objects can register themselves with the input system to be notified when certain things happen. There are different types of callbacks you could register, based on the type of input events observers would like to be notified ...


4

Here are some simple steps you can take just to get something up & running quickly, and not to be too ambitious: (1) For a frictionless effect, it sounds like your cube just needs to maintain a velocity vector (vx,vy,vz). Whenever the user presses a directional key, add or subtract some small fixed amount to this velocity vector. This way, on each ...


4

You didn't say what kind of game. I'd say the easiest usability solution is, find a similar game that has similar mechanics, something your players might be familiar with, and use the same keys. So, if your game is an action-RPG like Diablo, making the default keybindings work an awful lot like Diablo is not a horrible way to start. See: ...


4

Use the event driven API already provided for you, but instead of executing the events immediatly, queue and batch them to be executed in the next update iteration. Here's an example in C# which I suppose you'll be capable of adapting to Javascript. In this case all events will be executed during the next frame after they were created: var keyEventQueue = ...


4

David pretty much summed it up entirely. However, if you are interested I attached at the end a condensed version of what I use. It's just a game component you can add to the game with Components.Add() then call to check if buttons were just pressed, released, or are currently down. You can just throw it directly in your project (you might want to change the ...


4

SDL_PollEvent will not change the content of the event you pass through if there is no new event to report. This means that type == SDL_KEYDOWN will stay true until some other event arrives. You need to check the value returned from SDL_PollEvent and only continue on to your event handling code when there is a new event to handle. eg. if (SDL_PollEvent( ...


4

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.


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

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.


4

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 ...


3

In Natural Selection hotkeys were assigned to positions. If the command panel was something like: _____ |_|_|_| |_|_|_| |_|_|_| Shortcuts would be: _____ |Q|W|E| |A|S|D| |Z|X|C| You could also configure your own shortcuts, but the default was great because you just had to remember positions, not complex combinations of hotkeys. Also, it allowed me to ...


3

One way is to store the current and previous input states, and compare them every time that you poll the input. For each key that can be pressed, store an object that has a timestamp of the last time that the key switched from a down state to an up state. Update these objects by doing this at every poll: void update(){ some_key_has_been_pressed = ...


3

In SFML, you have the keys in the order they have been pressed with the KeyPressed event type. You process each key in a while(getNextEvent()). So if the pressed key is in your Key->Action map, run the corresponding action, and if it's not, forward it to any widget/stuff that might need it. Regarding your second question, I'd recommend you to keep it like ...


3

You may want to look into the keyboard layout called Dvorak for inspiration here. The Dvorak keyboard layout is designed such that the home row houses the most frequently pressed keys. The upper row (the one below the numbers) has the second most frequently used keys, and the bottom row has the keys with the lowest usage. For the Dvorak layout, I believe ...


3

When playing and you hit the P key your if(CurrentGameState == GameStates.Playing) block is executed, changing the state to paused. Then the if(CurrentGameState == GameStates.Paused) block that follows also runs (because you just changed the state to paused above and the P key state hasn't changed), changing the game state back to playing. This is why you ...


3

I'd say 2: as you state, solution 1 would generate too much traffic. There's a chance it works in the beginnings, but then when you'll add other things to send you might have to reduce the input updates frequency and thus you game reactivity. As a rule of thumb, sending deltas instead of complete states is most of the time The Right Thing to do. You're ...


3

While not technically a JAVA library SDL is a C library that I use extensively that does input and much more. It does however have bindings for java and can run on pretty much any platform in existence. http://www.libsdl.org/languages.php There is JSDL and SDLjava


3

I was thinking of creating a class that would sort of convert either input into a universal sort of data that the game could then use for the player's character and the rest of the game to interpret. This is the right idea. Use a abstract action codes instead of actual Key Codes or Button Codes. Not only does this let you support keyboard + gamepad, it ...



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