Beginner - DirectX and C++

Started by
4 comments, last by Brain 8 years, 10 months ago

Hello,

I have 2 question for you.

1. How do I make a folder inside the Documents folder? I want to save the settings there.

2. How do I add a keyboard and mouse input, like if you push on wasd, you can control a car etc.

- Jestin

Advertisement

1. How do I make a folder inside the Documents folder? I want to save the settings there.


Going off the assumption that you're using Windows (I don't think Linux has a "Documents" folder - Mac might?)

First off - application/game settings are typically stored in the application data folder, not the user's documents folder. The user's documents folder is more commonly used for save games.

Use SHGetKnownFolderPath to get the path to FOLDERID_Documents (for the documents folder) or FOLDERID_LocalAppData (for the data folder). Then add your folder name to the path with PathCombine (if you want to support older systems) or PathCchCombine (if you don't mind restricting your program to Windows 8 or newer).

Now that you have your path, you can use CreateDirectory to actually make the folder. Note that the parent folders need to exist, so if you want to do something like "MyCompany\MyGame" you'll have to create the MyCompany folder before you try creating MyGame.

I'll leave the answer of 2 to people more experienced with input systems, but to get raw keyboard and mouse input from Windows (i.e. button presses and mouse deltas), you'll want to use Raw Input. For text input and mouse cursor handling, use standard Windows messages.

For inputs you have 2 options:

  • Listen for WM_KEYDOWN and WM_KEYUP events.
  • Use Direct Input. (my recommendation). it is keyboard agnostic so WASD will be mapped to the same keys even on AZERTY keyboards.

Google around for Direct Input tutorials.

If you need text input, don't use neither of those. use the WM_CHAR event.

For inputs you have 2 options:

  • Listen for WM_KEYDOWN and WM_KEYUP events.
  • Use Direct Input. (my recommendation). it is keyboard agnostic so WASD will be mapped to the same keys even on AZERTY keyboards.
Google around for Direct Input tutorials.

If you need text input, don't use neither of those. use the WM_CHAR event.


Direct Input is not recommended as it has been depreciated by MS years ago and may be removed from Windows at any time.

It's basically a heavyweight wrapper around raw input anyway, so you're better off using that.

1. How do I make a folder inside the Documents folder? I want to save the settings there.


Going off the assumption that you're using Windows (I don't think Linux has a "Documents" folder - Mac might?)

First off - application/game settings are typically stored in the application data folder, not the user's documents folder. The user's documents folder is more commonly used for save games.

Use SHGetKnownFolderPath to get the path to FOLDERID_Documents (for the documents folder) or FOLDERID_LocalAppData (for the data folder). Then add your folder name to the path with PathCombine (if you want to support older systems) or PathCchCombine (if you don't mind restricting your program to Windows 8 or newer).

Now that you have your path, you can use CreateDirectory to actually make the folder. Note that the parent folders need to exist, so if you want to do something like "MyCompany\MyGame" you'll have to create the MyCompany folder before you try creating MyGame.

I'll leave the answer of 2 to people more experienced with input systems, but to get raw keyboard and mouse input from Windows (i.e. button presses and mouse deltas), you'll want to use Raw Input. For text input and mouse cursor handling, use standard Windows messages.

Oh thanks for the tip to save it in the data folder :) I will try

Always use Windows messages for key presses.

Move your windows message loop into a separate thread to the game loop and buffer the keyboard input processing a set amount of messages each iteration of the loop so that input is deterministic and a fixed speed like your frame rate.

This is because you otherwise have to reimplement keyboard repeat etc for entering text, think where the player enters their name into a high score table or types a chat message.

For joysticks etc you could consider xinput which is good for xbox controllers etc.

This topic is closed to new replies.

Advertisement