title: Hooking Direct Input
body: <p><strong>INTRODUCTION</strong></p>
  
  <p>There's this old fullscreen 800x600 or windowed mode online game binary I would like to make a new GUI for, using <strong>C++</strong>. I haven't got its source code. Same interface yet scaled to occupy most of the screen as fullscreen while avoiding the game being distorted by stretching into a monitor with a different resolution, besides allowing app switching while keeping native resolution. So far I've successfully made a window paint itself with the windowed game window content scaled, and redirected both it's keyboard input and all the window activation messages into the windowed game window in the background. I'm currently struggling to send the remapped cursor position and clicks. </p>
  
  <p><strong>MY ATTEMPTS</strong></p>
  
  <p>I first tried sending <code>WM_MOUSEMOVE</code> messages but found out the game uses Direct Input. Suspending or killing the <em>dinput8.dll!GetdfDIJoystick+0x61c8</em> game thread with Process Explorer stops the game from reacting to mouse input.</p>
  
  <p><a href="https://stackoverflow.com/a/410161/4059652">This</a> StackOverflow answer states:</p>
  
  <blockquote>
    <p>...it's worth noting that in recent versions of Windows, DirectInput for mouse &amp; keyboard input is just a wrapper around the Win32 windows messages...</p>
  </blockquote>
  
  <p>... so I also tried intercepting that thread messages. I inspected a window called <em>DIEmWin</em> using Spy++, which seems to be spawned by Direct Input and belonging to the game process, and saw it was receiving <code>WM_INPUT</code> messages. I installed a <code>WH_GETMESSAGE</code> hook into its thread and stopped these messages avoiding their <code>CallNextHookEx()</code> call. Rehooking the same window with Spy++ showed no more <code>WM_INPUT</code> messages being received, yet the game was still reacting to mouse input. I then tried adding a <code>WH_MOUSE_LL</code> hook on top of that, despite Spy++ showing no related messages to that thread, just in case. Game still reacting to mouse input.</p>
  
  <p><strong>MY QUESTION</strong></p>
  
  <p>How can I go about remapping the cursor position without using detours? I was hoping to achieve my objective by hooking this theoretical Direct Input wrapper, and thus avoiding the need to inject assembly code into the game Direct X 8 calls. I believe I've successfully intercepted all this wrapper messages and yet game reacts to input anyways.</p>
  
  <p><em>Some notes</em>:</p>
  
  <ul>
  <li><p>The redirected keyboard input is probably non existing and happening because of the game window receiving an activation message while on the background and Direct Input getting keyboard input as is.</p></li>
  <li><p>I haven't got access to a way of signing drivers without cost.</p></li>
  </ul>