t2:gpc_scripting:usb_hid

USB HID

… WORK IN PROGRESS …

The Output Protocol “USB Multi Interface HID” is a bit special.
It allows the Output to be send as keyboard, mouse and gamepad controls. The connect console/PC on the T2 Output Port will see the T2 as a keyboard/mouse.

This requires different scripting approaches than the usual console controller output protocols. Instead of “set_val” you have to use mouse_set (for mouse output) or key_set (for keyboard output).

Utilizing this “USB Multi Interface HID” Output Protocol you can do scripting with the T2 for the PC. Pablosscripts created a forum post with some information about it: Pablo's Beginners Guide to Scripting for PC

You can find a few scripts for this protocol in the Online Resource within GTuner IV: Search for “usb-hid”.
Some USB Script specific forum links:
USB-HID Anti Recoil (USB Multi Interface HID)
USB-HID Gamepad 2 Keyboard+Mouse (USB Multi Interface HID)

GPC functions

Important GPC functions for USB HID protocol usage:
Keyboard: keymapping key_passthru key_check key_status key_get key_set
Mouse: mousemapping mouse_passthru mouse_status mouse_get mouse_set

When you want to forward mouse input or keyboard input use the corresponding _passthru function.
As soon as you want to alter the input before outputting it you need to be careful:

Combination of mouse_passthru() with mouse_set() : The first function will overwrite the output buffer with the latest data received from the connected mouse

More information:
mouse_passthru and mouse_set
mouse_set: always set all mouse ouputs -> X/Y/Wheel/Buttons

Examples

Basic

A very basic example to forward all mouse and keyboard input to the output port will look like this:

init{
  mousemapping(); // clears defaultt T2 mouse mappings
  keymapping(); // clears default T2 keyboard mappings
}
main{
  mouse_passthru(); // forward mouse input to output
  key_passthru(); // forward keyboard input to output
}

Anti Recoil

When mouse button 1 is pressed the anti recoil will be applied.

#include <mouse.gph>
 
// configuration
const int mouse_speed = 10; // <- should be around 10 or higher, a value too low can stop the mouse from working!
const int Relative_X = 0; // anti recoil horizontal
const int Relative_Y = 1; // anti recoil vertical
 
// internal
int32 X, Y, WHEEL;
int32 RX, RY;
 
init {
  keymapping();
  mousemapping();
}
 
main {
  key_passthru();
 
  RX = 0; RY = 0;
  X = 0; Y = 0; WHEEL = 0;
 
  if(mouse_status(MREPORT_UPDATED)) {
      mouse_passthru(); // only passthru when there is data to send
      X = mouse_status(MOUSE_X);
      Y = mouse_status(MOUSE_Y);
      WHEEL = mouse_status(MOUSE_WHEEL);
  }
 
  if(mouse_status(MBUTTON_1))
  {
    if(!(system_time()%mouse_speed)) {
        RX = Relative_X;
        RY = Relative_Y;
        mouse_set(MOUSE_X, X+RX);
        mouse_set(MOUSE_Y, Y+RY);
        mouse_set(MOUSE_WHEEL,WHEEL);
    }
  }
}

… WORK IN PROGRESS …

t2/gpc_scripting/usb_hid.txt · Last modified: 2019/11/13 05:57 by scachi