That mini joystick has a spring to autocenter it, right ? You'd better not use this like an absolute-positionning, it would be hard to maintain the position and click the same time.
I did the same with an old PS2 minijoystick connected to a VM110 board. (sensors range from 0 to 255)
GetCursorPos(PosXY);
DeltaX:=Trunc((((-25/3072)*(127-Data1)+1075/96)*(127-Data1)/1000)*Abs(127-Data1));
DeltaY:=Trunc((((-25/3072)*(127-Data2)+1075/96)*(127-Data2)/1000)*Abs(127-Data2));
PosXY.X:=PosXY.X + DeltaX;
PosXY.Y:=PosXY.Y - DeltaY;
SetCursorPos(PosXY.X,PosXY.Y);
Maths are there to alter linearity.
And to emulate a left click (switch connected to input 1, (i and 1) checks if input #1 is 0/1)
if (i and 1)>0 then
begin
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
sleep(20);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
end;



LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks