home | login | register | DMCA | contacts | help | donate |      

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z


my bookshelf | genres | recommend | rating of books | rating of authors | reviews | new | | collections | | | add
fantasy
space fantasy
fantasy is horrors
heroic
prose
  military
  child
  russian
detective
  action
  child
  ironical
  historical
  political
western
adventure
adventure (child)
child's stories
love
religion
antique
Scientific literature
biography
business
home pets
animals
art
history
computers
linguistics
mathematics
religion
home_garden
sport
technique
publicism
philosophy
chemistry
close

Loading...


Setting up the mouse

As with the keyboard, we need to set up the mouse before we can get access to it. Below is the code required, take a look and you'll notice that it is very similar to the keyboard set up code above.

//MOUSE =======================================================================

//Create the mouse device object

if (FAILED(m_pDirectInput->CreateDevice(GUID_SysMouse, &m_pMouse, NULL))) {

CleanUpDirectInput();

LogError("

  • Unable to create DirectInput mouse device interface.");

    return false;

    } else {

    LogInfo("

  • DirectInput mouse device interface created OK.");

    }

    //Set the data format for the mouse

    if (FAILED(m_pMouse->SetDataFormat(&c_dfDIMouse))) {

    CleanUpDirectInput();

    LogError("

  • Unable to set the mouse data format.");

    return false;

    } else {

    LogInfo("

  • Set the mouse data format OK.");

    }

    //Set the cooperative level for the mouse

    if (FAILED(m_pMouse->SetCooperativeLevel(hWnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE))) {

    CleanUpDirectInput();

    LogError("

  • Unable to set the mouse cooperative level.");

    return false;

    } else {

    LogInfo("

  • Set the mouse cooperative level OK.");

    }

    //Acquire the mouse

    if (m_pMouse) {

    m_pMouse->Acquire();

    }

    So, for the mouse we have the same basic steps as for the keyboard. One of the differences is that we pass in the predefined GUID for the system mouse (GUID_SysMouse) into the CreateDevice method instead of the one for the keyboard which will return a pointer to the mouse. Another difference is that we need to use a different data format, c_dfDIMouse instead of c_dfDIKeyboard. We then set the cooperation level as before and finally acquire the mouse. We are now ready to get data from the keyboard and mouse.


  • Setting up the keyboard | DirectX 8 Programming Tutorial | Buffered and Immediate Data







    Loading...