Hello,
im not necessarily new to c++ but i cant seem to find a good way to get input from other devices other then the keyboard. To get keyboard input i have been using GetAsyncKeyState(); i was wondering if there was a similar function to get input from other input devices such as game pads or the proprietary buttons found on most laptops and keyboards these days (Media Direct buttons, volume up, down, skip, launch internet browser, etc)
i read somewhere about DirectInput(); but i dont no if its exactly what im looking for, any incite?

thank you in advance,
--twek

Dani AI

Generated

Short summary and practical route: asked about reading input from gamepads and the special media/hotkeys on laptops; correctly pointed at a cross‑platform library for controllers. For Windows, choose the API based on what you actually need to see — high‑level media commands, standard gamepads, or raw HID reports — because they’re exposed differently by the OS and by vendor drivers. (learn.microsoft.com)

If the target is modern Xbox/PC gamepads, prefer the XInput controller API for a simple, well‑supported interface; for device‑level access (to distinguish two identical mice/keyboards or to read consumer HID usages) use the Raw Input/HID route so the app receives WM_INPUT with raw HID data. WM_APPCOMMAND is the higher‑level message the system uses for common media keys, but it won’t give you device‑specific HID details. For guidance on differences and how to combine approaches, see Microsoft’s controller and raw‑input docs. (learn.microsoft.com)

For cross‑platform work, SDL’s joystick/gamecontroller APIs are the easiest way to support a wide range of controllers without platform code; SDL maps many controllers to a common layout but won’t necessarily expose vendor‑specific laptop “launch” buttons. For low‑level USB/Bluetooth HID access across OSes use a library such as HIDAPI to read consumer control reports directly. (wiki.libsdl.org)

Quick checklist to apply immediately: 1) Identify whether the button generates a WM_APPCOMMAND/virtual key or a consumer‑control HID report (use a USB/HID viewer or HIDAPI test tools). 2) If it’s a standard gamepad, try XInput or SDL first. 3) If it’s a consumer HID or vendor hotkey and you see nothing, the OEM utility may be intercepting it — check for vendor SDKs or use raw HID or low‑level hooks as a fallback. 4) If you need legacy device support, plan to handle XInput and DirectInput cases separately. (learn.microsoft.com)

This approach avoids guessing which layer the key lives in and lets you pick the simplest, most robust API for the device class you actually need to read.

Recommended Answers

All 2 Replies

You can use SDL:

Simple DirectMedia Layer (SDL) is a cross-platform, free and open source software multimedia library written in C that presents a simple interface to various platforms' graphics, sound, and input devices, allowing a developer to write a computer game or other multimedia application that can run on many operating systems including Linux, Syllable, Haiku/BeOS, Windows, Mac OS X, AmigaOS and its clone MorphOS. It manages video, events, digital audio, CD-ROM, sound, threads, shared object loading, networking and timers[1].

This site has tutorials about it.

thanks, ill look at it tmrw this does look like a better alternative then directx lol but can i use it to access my media direct hardware button on my laptop?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.