Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy can I not acquire the keyboard with DirectInput?
    primarykey
    data
    text
    <p>I just started getting into DirectInput today, using DirectInput8 with <a href="http://nuwen.net/mingw.html" rel="nofollow">MinGW</a> on Windows 7 Ultimate N. I started off with a simple program to report which keys are currently down every second (just codes, not readable keys). However, I can't even get as far as acquiring the keyboard before it errors out:</p> <pre><code>#define _WIN32_WINNT 0x0601 #include &lt;dinput.h&gt; //link to dinput8.lib and dxguid.lib int main() { IDirectInput8 *dinput; DirectInput8Create(GetModuleHandle(nullptr), DIRECTINPUT_VERSION, IID_IDirectInput8, (void **)&amp;dinput, nullptr); IDirectInputDevice8 *kb; dinput-&gt;CreateDevice(GUID_SysKeyboard, &amp;kb, nullptr); kb-&gt;SetDataFormat(&amp;c_dfDIKeyboard); kb-&gt;SetCooperativeLevel(GetConsoleWindow(), DISCL_FOREGROUND | DISCL_NONEXCLUSIVE); kb-&gt;Acquire(); //fails with DIERR_INVALIDPARAM } </code></pre> <p>I omitted error checking, but what happens is that every call succeeds (by judgement of the <code>FAILED</code> macro) up to <code>Acquire()</code>. That call fails with the error <code>DIERR_INVALIDPARAM</code>. I looked on the MSDN pages and across the web, but I can't find any reason it would fail with that based on everything before it present and working.</p> <p>For good measure, I also tried looping the <code>Acquire()</code> call until it succeeded and then played around with windows and the keyboard while it was running, but the program never successfully acquired the keyboard in all the time it was running. How can I successfully acquire the keyboard?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload