Skip to content

Instantly share code, notes, and snippets.

@kleinerm
Created January 30, 2012 14:37
Show Gist options
  • Save kleinerm/1704730 to your computer and use it in GitHub Desktop.
Save kleinerm/1704730 to your computer and use it in GitHub Desktop.
Do your own mouse driver as M-File via raw HID access. Version for "8-Bit mouse'
function [ dx, dy, sx, sy ] = RawMouse(devIndex)
persistent sx;
persistent sy;
if isempty(sx)
sx = 0;
sy = 0;
end
dx = 0;
dy = 0;
if nargin < 1 || isempty(devIndex)
devIndex = 1;
end
PsychHID('ReceiveReports', devIndex);
reps = PsychHID('GiveMeReports', devIndex);
for i=1:numel(reps)
rep = reps(i).report;
if ~isempty(rep)
if rep(4) ~= 0
fprintf('FOO: %i : %i %i\n', rep(4), rep(2), rep(3));
end
dx = double(rep(2));
if dx >= 128
dx = dx - 256;
end
dy = double(rep(3));
if dy >= 128
dy = dy - 256;
end
sx = sx + dx;
sy = sy + dy;
end
end
return;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment