Sign in to follow this  

DirectInput newb question

Recommended Posts

I know that keyboard devices can be accessed as immediate states or buffered data. Does the mouse have similar buffered data or just the state? If so, how is the mouse's buffer accessed? Thanks for your time and consideration, FenixRoA

Share this post

Link to post
Share on other sites
Yes, here is what the documents say about this:


Preparing for Buffered Input from the Mouse


The Scrawl application demonstrates how to use event notification to find out about mouse activity, and how to read buffered input from the mouse. Both of these techniques require some setup. You can perform these steps at any time after creating the mouse device and before acquiring it.

First, create an event and associate it with the mouse device. You are instructing Microsoft® DirectInput® to notify the mouse device object whenever a hardware interrupt indicates that new data is available.

This is how it is done in Scrawl, where g_hevtMouse is a global HANDLE.

g_hMouseEvent = CreateEvent(NULL, FALSE, FALSE, NULL);

if (g_hMouseEvent == NULL) {
return FALSE;

hr = g_pMouse->SetEventNotification(g_hMouseEvent);

if (FAILED(hr)) {
return FALSE;

Now set the buffer size so that DirectInput can store any input data until you are ready to view it. Note that by default the buffer size is zero, so this step is essential if you want to use buffered data.

It is not necessary to used buffered data with event notification. If you prefer, you can retrieve immediate data when an event is signaled.

To set the buffer size, initialize a DIPROPDWORD structure with information about itself and about the property you want to set. Most of the values are boilerplate. The key value is the last one, dwData, which is initialized with the number of items you want the buffer to hold.


// the header
dipdw.diph.dwSize = sizeof(DIPROPDWORD);
dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
dipdw.diph.dwObj = 0;
dipdw.diph.dwHow = DIPH_DEVICE;
// the data
dipdw.dwData = SAMPLE_BUFFER_SIZE;

You then pass the address of the header (the DIPROPHEADER structure within the DIPROPDWORD structure ), along with the identifier of the property you want to change, to the IDirectInputDevice8::SetProperty method, as follows:

hr = g_pMouse->SetProperty(DIPROP_BUFFERSIZE, &dipdw.diph);

if (FAILED(hr)) {
return FALSE;

The setup is now complete, and you are ready to acquire the mouse and start collecting data.

If you wish to see this, go to the documents, then:

Direct Input->DirectInput C/C++ Tutorials->Tutorial 2: Using the Mouse -> Step 4

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this