Checking for devices...

This is a discussion on Checking for devices... within the C++ Programming forums, part of the General Programming Boards category; I'm using Dev-C++ 4.9.9.1 on Windows XP Home Edition, and I am wondering if there is a way to see ...

  1. #1
    Rabite SirCrono6's Avatar
    Join Date
    Nov 2003
    Location
    California, US
    Posts
    269

    Checking for devices...

    I'm using Dev-C++ 4.9.9.1 on Windows XP Home Edition, and I am wondering if there is a way to see if the mouse and the keyboard are plugged into the computer. Like:
    Code:
    if( !MousePluggedIn )
    {
      std::cout << "No mouse!";
    }
    else if( !KeyboardPluggedIn )
    {
      std::cout << "No keyboard!";
    }
    or something along those lines. Thanks.

    - SirCrono6
    From C to shining C++!

    Great graphics, sounds, algorithms, AI, pathfinding, visual effects, cutscenes, etc., etc. do NOT make a good game.
    - Bubba

    IDE and Compiler - Code::Blocks with MinGW
    Operating System - Windows XP Professional x64 Edition

  2. #2
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903

    #include<windows.h>

    I can't find anything to determine if a keyboard is available, but I can answer your mouse question.

    Using Win32API, you can determine if the mouse is available by:
    Code:
    fMouse = GetSystemMetrics(SM_MOUSEPRESENT);
    The value of fMouse will be TRUE (nonzero) if a mouse is installed and 0 if mouse is not installed.
    (However in Windows 98 this functions always returns TRUE whether a mouse is attached or not)


    To determine the number of mouse buttons:
    Code:
    cButtons = GetSystemMetrics(SM_CMOUSEBUTTONS);
    Last edited by The Brain; 03-28-2005 at 08:55 PM.
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  3. #3
    Rabite SirCrono6's Avatar
    Join Date
    Nov 2003
    Location
    California, US
    Posts
    269
    According to MSDN, GetSystemMetrics( SM_MOUSEPRESENT ) returns non-zero if there is a mouse installed and zero if there isn't. I tested this: mouse in was true and mouse out was true. This seems to be because the mouse is installed whether or not it is plugged into the computer. Thanks anyways

    - SirCrono6
    From C to shining C++!

    Great graphics, sounds, algorithms, AI, pathfinding, visual effects, cutscenes, etc., etc. do NOT make a good game.
    - Bubba

    IDE and Compiler - Code::Blocks with MinGW
    Operating System - Windows XP Professional x64 Edition

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Array bounds checking
    By rohan_ak1 in forum C Programming
    Replies: 2
    Last Post: 08-26-2008, 11:16 PM
  2. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 10:38 AM
  3. Interpreter.c
    By moussa in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 06:59 PM
  4. Forced moves trouble!!
    By Zishaan in forum Game Programming
    Replies: 0
    Last Post: 03-27-2007, 07:57 PM
  5. Problems about gcc installation
    By kevin_cat in forum Linux Programming
    Replies: 4
    Last Post: 08-09-2005, 10:05 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21