PDA

View Full Version : Raw Input in QT4



been_1990
25th August 2010, 13:15
Does QT4 support raw input? Is there a way to use it?

yakin
25th August 2010, 13:21
What do you mean with "raw input". Any context?

been_1990
28th August 2010, 16:49
Yes, Raw Input as in input from a game controller.
http://msdn.microsoft.com/en-us/library/ms645546%28v=VS.85%29.aspx
But I want to be able to connect various USB mouse to a pc and then get each of their input separately.

tbscope
28th August 2010, 17:02
No, I don't think this capability is in Qt.

You can of course use the functions suggested by MSDN.
But it won't be multiplatform.

On unix systems you can just get the input from a device like this:

cat /dev/input/mouse0
(þ(þ(û(ü(û(ü(ú(û(ý(þ (þ(ÿ(ÿ(þ(þ(þ(ý(ý(ý(ý (ÿ(ý(ý(ý(ý(ý(ÿ(ý(ý(þ (ý(ý(þ(þ(þ(ý(ÿ(þ(ÿ(ÿ (ÿ(ÿ(þ(ý(þ(þ(ÿ(þ(ÿ(ÿ (ÿ(ÿ(ÿ(ý(þ(þ(ý(ÿ(þ(ÿ (ÿ(þ(ÿ(ÿ(ÿ(ÿ((ÿ(þ(ÿ(à¿(ÿ^C

been_1990
13th September 2010, 03:48
Ok, I found a app that uses Win32 to get raw input.


raw_mouse.h:

//================================================== ===============
//
// raw_mouse.h - Windows XP implementation of multi-mouse input
//
//================================================== ===============

#ifndef __RAW_MOUSE_H
#define __RAW_MOUSE_H

#include <windows.h>
#include <stdio.h>

//================================================== ==========
// PROTOTYPES
//================================================== ==========
// init raw mouse by creating the array of raw mice (include sysmouse, include rawmouse, include individual mice)
BOOL init_raw_mouse(BOOL, BOOL, BOOL);

// Number of mice stored in pRawMice array
// NOTE: init_raw_mouse must be called before this can return the actual number of mice
int raw_mouse_count();



// Free up the memory allocated for the raw mouse array
void destroy_raw_mouse(void);

// Every time the WM_INPUT message is received, the lparam must be passed to this function to keep a running tally of
// every mouse move to maintain accurate results for get_raw_mouse_x_delta() & get_raw_mouse_y_delta().
BOOL add_to_raw_mouse_x_and_y(HANDLE); // device handle, x val, y val

// Fetch the relative position of the mouse since the last time get_raw_mouse_x_delta() or get_raw_mouse_y_delta
// was called
ULONG get_raw_mouse_x_delta(int);
ULONG get_raw_mouse_y_delta(int);
ULONG get_raw_mouse_z_delta(int);

// pass the mousenumber, button number, returns 0 if the button is up, 1 if the button is down
BOOL is_raw_mouse_button_pressed(int, int);
char *get_raw_mouse_button_name(int, int);

// Used to determine if the HID is using absolute mode or relative mode
// The Act Labs PC USB Light Gun is absolute mode (returns screen coordinates)
// and mice are relative mode (returns delta)
// NOTE: this value isn't updated until the device registers a WM_INPUT message
BOOL is_raw_mouse_absolute(int);

// This indicates if the coordinates are coming from a multi-monitor setup
// NOTE: this value isn't updated until the device registers a WM_INPUT message
BOOL is_raw_mouse_virtual_desktop(int);

#endif /* ifndef __RAW_MOUSE_H */


So I include the C file:

extern "C"{
#include "raw_mouse.h"
}
And call the initialization function, then check for amount of raw mouse inputs:

init_raw_mouse(1,0,1);
qDebug() << raw_mouse_count();
But that outputs 0. When it should show 5.That's what the original Win32 app displays.

been_1990
13th September 2010, 18:54
With some help I've got that figured out. Subclassed QApplication and here's the result:

extern "C"{
#include "raw_mouse.h"
}
#include "qapp.h"
#include <QDebug>
#define WM_INPUT 0x00FF

QApp::QApp(int & argc, char ** argv) :
QApplication(argc,argv)
{
init_raw_mouse(1, 0, 1);
qDebug() << raw_mouse_count();
}

bool QApp::winEventFilter(MSG *message, long *result)
{
qDebug() << message->message;
switch(message->message){
case WM_INPUT:
{
add_to_raw_mouse_x_and_y((HANDLE)message->lParam);
qDebug() << "raw input here";
}
return true;
}
return false;
}

The problem is that "raw input here" never traces, so I never get the raw input. Also raw_mouse_count() prints 0 when it should print out at least 5.