From 733d114815223d85f59bb6c616cd1f7475b4754b Mon Sep 17 00:00:00 2001 From: TimothyLottes Date: Thu, 10 Nov 2016 08:32:25 -0500 Subject: [PATCH] Add files via upload --- 20130325.html | 14 ++++++++++++++ index.html | 2 ++ 2 files changed, 16 insertions(+) create mode 100644 20130325.html diff --git a/20130325.html b/20130325.html new file mode 100644 index 0000000..5c73192 --- /dev/null +++ b/20130325.html @@ -0,0 +1,14 @@ +
+

20130325 - Understanding WIN32 GetRawInputBuffer()

+
+ +This is a re-post, for some reason bringing back the prior link is no longer working, have not figured out why yet. +Direct link to docs: GetRawInputBuffer(). +
+
+On XP at least (have not tested Vista/Win7/Win8 yet),
The entire RawInput system is built on-top of WM_INPUT events in the standard Window's message queue. When processing messages, WM_INPUT messages must not be removed in order to use GetRawInputBuffer() as GetRawInputBuffer() will use then remove those events. In my usage case I'm doing this to drain out the message queue without disrupting GetRawInputBuffer(), and relying on the fact that for events like WM_ACTIVATEAPP (ALT+TAB), PeekMessage() automatically calls the WinProc() without returning the message to the application directly,

while(1) {
if(PeekMessage(&msg, 0, 0, WM_INPUT-1, PM_NOYIELD | PM_REMOVE) == 0) break;
DefWindowProc(msg.hwnd, msg.message, msg.wParam, msg.lParam); }
while(1) {
if(PeekMessage(&msg, 0, WM_INPUT+1, 0xFFFFFFFF, PM_NOYIELD | PM_REMOVE) == 0) break;
DefWindowProc(msg.hwnd, msg.message, msg.wParam, msg.lParam); }

GetRawInputBuffer()
Docs on GetRawInputBuffer() are confusing, here is a less confusing example,

// Some temp global buffer, 1KB is overkill.
static uint64_t rawBuffer[1024/8];
...
// Then in some function,
const uint32_t bytes = sizeof(rawBuffer);
// Loop through reading raw input until no events are left,
while(1) {
// Fill up buffer,
int32_t count = GetRawInputBuffer((PRAWINPUT)rawBuffer, &bytes, sizeof(RAWINPUTHEADER));
if(count <= 0) return;
...
// Process all the events,
const RAWINPUT* restrict raw = (const RAWINPUT* restrict) rawBuffer;
while(1) {
// Process raw event.
...
// Goto next raw event.
count--;
if(count <= 0) break;
raw = NEXTRAWINPUTBLOCK(raw); } }
+ +
+ + + diff --git a/index.html b/index.html index 8e74c85..3fd8106 100644 --- a/index.html +++ b/index.html @@ -103,10 +103,12 @@ Below this is active random migration (416 prior posts still to filter through) 20140715 - Infinte Projection Matrix Notes
20140506 - The Other Project
20140328 - Related to Filtering for VR
+20140110 - Portable Read-Only Thumb Linux

2013
20131126 - Random Next Generation Notes
20130825 - Modern Memory Mapping
+20130325 - Understanding WIN32 GetRawInputBuffer()

2012
20121203 - Simple Custom Web Server Tricks