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

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


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


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


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?


6

it's still keyboard hardware limitations. http://en.wikipedia.org/wiki/Rollover_%28key%29


6

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


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

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


5

I'd never expect shortcuts to be in my language. Pretty much everyone who plays games knows English, it became a standard, and it's always a good idea to keep up to the standard. So stick with English.


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

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


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

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

It looks like you want to do something like: _vausSpacecraftPos.X += _vausSpacecraftSpeed.X; -- you may also want to scale by the elapsed time stored in the GameTime object so you get frame-rate independent movement.


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

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


4

I'm assuming you're using Windows so I did some digging and I found this answer on a question on the Microsoft forums about if it is possible to discern multiple keyboards: No, this is dealt with at the device driver level. Beyond those, it can no longer tell where the keystroke came from. ...


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

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

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

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



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