Just in case the following code is of value to others in a joystick information search.
Code:
/***************** MODIFIED "input.cpp" SAMPLE CODE ****************************/
#include "stdafx.h"// point position
/******************************************************************************/
Vec2 point, // point position
axis, // x,y joystick values
extra, // rudder,throttle values
tophat; // tophat vectors
Char c; // character pressed
enum {TRIGGER,BUTTON2,BUTTON3,BUTTON4,BUTTON5,BUTTON6,BUTTON7,BUTTON8};
enum {JOYPAD1,JOYPAD2,JOYPAD3,JOYPAD4};
InputButton JoyButton(INPUT_JP,TRIGGER,JOYPAD1,NULL); // InputButton(INPUT_TYPE type, Byte button, Byte device=0, Bool (*req)()=NULL)
/******************************************************************************/
void InitPre()
{
App.name("Input");
App.flag=APP_NO_FX;
PakAdd("../data/engine.pak");
}
/******************************************************************************/
Bool Init()
{
Text_ds.color =BLACK; // here change the default text color
Text_ds.shadow=0; // here disable shadows
return true;
}
/******************************************************************************/
void Shut()
{
}
/******************************************************************************/
Bool Main()
{
if(Kb.bp(KB_ESC))return false;
if(Kb.c())c=Kb.c(); // if character pressed remember to draw it later
if(Kb.b(KB_LEFT ))point.x-=Tm.d()/2; // move point left when 'left arrow' is on according to time delta
if(Kb.b(KB_RIGHT))point.x+=Tm.d()/2; // move point right when 'right arrow' is on according to time delta
if(Kb.b(KB_DOWN ))point.y-=Tm.d()/2; // move point down when 'down arrow' is on according to time delta
if(Kb.b(KB_UP ))point.y+=Tm.d()/2; // move point up when 'up arrow' is on according to time delta
if(Kb.bp(KB_Z))point.x-=0.1; // when 'z' is pushed , move point left
if(Kb.br(KB_X))point.x+=0.1; // when 'x' is released , move point right
if(Kb.bd(KB_C))point.y+=0.1; // when 'c' is double clicked, move point up
return true;
}
/******************************************************************************/
void Draw()
{
D.clear(WHITE);
D.dot(RED ,Ms.pos); // draw red dot at mouse cursor position
D.dot(GREEN,point ); // draw green dot at 'point' position
if(Ms.b(0))D.dot(BLACK, -0.1,0.4, 0.1); // when 0th mouse button on, draw big black dot
if(Ms.b(1))D.dot(BLACK, 0.1,0.4, 0.1); // when 1st mouse button on, draw big black dot
D.text(0,0.9, S+"character : "+c ); // draw stored character
D.text(0,0.7, S+"mouse : "+Ms.pos); // draw mouse position
D.text(0,0.6, S+"point : "+point ); // draw point position
axis = Jp[0].dir_a[0];
D.text(0,0.5, S+"Joystick x : "+axis.x ); // draw joystick x value
D.text(0,0.4, S+"Joystick y : "+axis.y ); // draw joystick y value
extra = Jp[0].dir_a[1];
D.text(0,0.3, S+"Joystick extraA(rudder) : "+extra.x ); // draw joystick rudder value
D.text(0,0.2, S+"Joystick extraA(throttle) : "+extra.y ); // draw joystick throttle value
tophat = Jp[0].dir;
D.text(0,0.1, S+"JoystickTophat Vec x : "+tophat.d[0] +" JoystickTophat Vec y : "+tophat.d[1] ); // draw joystick tophat Vec value
JoyButton.button=TRIGGER;
D.text(0,0.0, S+"Joystick JoyButton(button 0)=Stick(button 1) : "+JoyButton.on() ); // draw trigger state
JoyButton.button=BUTTON8;
D.text(0,-0.1, S+"Joystick JoyButton(button 7)=Stick(button 8) : "+JoyButton.on() ); // draw button state
}
/******************************************************************************/
A code fragments section on this forum would be a handy idea for this sort of material.