Site Tools
t2:gpc_scripting:usb_hid
Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
t2:gpc_scripting:usb_hid [2021/01/24 05:27] scachi [Anti Recoil] |
t2:gpc_scripting:usb_hid [2021/03/27 05:53] (current) scachi [Keyboard to Keyboard] |
||
---|---|---|---|
Line 96: | Line 96: | ||
// configuration | // configuration | ||
- | const fix32 antirecoil_X = 0.0; // anti recoil horizontal | + | fix32 antirecoil_X = 0.0; // anti recoil horizontal |
- | const fix32 antirecoil_Y = 0.5; // anti recoil vertical | + | fix32 antirecoil_Y = 0.5; // anti recoil vertical |
// advanced configuration | // advanced configuration | ||
Line 135: | Line 135: | ||
if (antirecoil_X < 0.0) RX += (int)ceil((ARX)); | if (antirecoil_X < 0.0) RX += (int)ceil((ARX)); | ||
- | else RX += (int)floor((ARX)); | + | else if (antirecoil_X > 0.0) RX += (int)floor((ARX)); |
| | ||
if (antirecoil_Y < 0.0) RY += (int)ceil((ARY)); | if (antirecoil_Y < 0.0) RY += (int)ceil((ARY)); | ||
- | else RY += (int)floor((ARY)); | + | else if (antirecoil_Y > 0.0) RY += (int)floor((ARY)); |
| | ||
mouse_set(MOUSE_X, X+RX); | mouse_set(MOUSE_X, X+RX); | ||
Line 159: | Line 159: | ||
<code gpc2> | <code gpc2> | ||
#include <keyboard.gph> | #include <keyboard.gph> | ||
+ | #include <mouse.gph> | ||
init { | init { | ||
Line 166: | Line 167: | ||
main { | main { | ||
key_passthru(); | key_passthru(); | ||
- | mouse_passthru(); | + | if(mouse_status(MREPORT_UPDATED)) { |
+ | mouse_passthru(); | ||
+ | } | ||
// dpad up mapping to key E | // dpad up mapping to key E | ||
Line 177: | Line 180: | ||
<code gpc2> | <code gpc2> | ||
#include <keyboard.gph> | #include <keyboard.gph> | ||
+ | #include <mouse.gph> | ||
init { | init { | ||
Line 184: | Line 188: | ||
main { | main { | ||
key_passthru(); | key_passthru(); | ||
- | mouse_passthru(); | + | if(mouse_status(MREPORT_UPDATED)) { |
+ | mouse_passthru(); | ||
+ | } | ||
// dpad up mapping to key E | // dpad up mapping to key E | ||
Line 202: | Line 208: | ||
</code> | </code> | ||
+ | ==== Keyboard to Keyboard ==== | ||
+ | Mapping keyboard input to keyboard HID output. | ||
+ | Useful for some games where you can't change the key assigned to actions. | ||
+ | <code gpc2> | ||
+ | #include <keyboard.gph> | ||
+ | #include <mouse.gph> | ||
+ | |||
+ | init { | ||
+ | port_connect(PORT_USB_C, PROTOCOL_HID); | ||
+ | keymapping(); | ||
+ | mousemapping(); | ||
+ | } | ||
+ | |||
+ | |||
+ | main { | ||
+ | key_passthru(); | ||
+ | if(mouse_status(MREPORT_UPDATED)) { | ||
+ | mouse_passthru(); | ||
+ | } | ||
+ | |||
+ | // shift <-> ctrl | ||
+ | keyMap(KEY_LEFTSHIFT, KEY_LEFTCONTROL); | ||
+ | keyMap(KEY_LEFTCONTROL, KEY_LEFTSHIFT, FALSE, KEY_LEFTSHIFT); // <-- for circular mapping | ||
+ | |||
+ | // additional shift mapping : alt -> shift | ||
+ | keyMap(KEY_LEFTALT, KEY_LEFTSHIFT, TRUE); // <-- for additional key to same destination | ||
+ | |||
+ | // caps -> alt | ||
+ | keyMap(KEY_CAPSLOCK, KEY_LEFTALT); | ||
+ | |||
+ | // left-> page down | ||
+ | keyMap(KEY_LEFTARROW, KEY_PAGEDOWN); | ||
+ | |||
+ | // right-> page up | ||
+ | keyMap(KEY_RIGHTARROW, KEY_PAGEUP); | ||
+ | } | ||
+ | |||
+ | |||
+ | void keyMap(uint8 keySrc, uint8 keyDst, bool noset, uint8 keyCheck) { | ||
+ | if (key_status(keySrc)) { | ||
+ | if (!keyCheck) key_set(keySrc, FALSE); | ||
+ | else if (!key_status(keyCheck)) key_set(keySrc, FALSE); | ||
+ | keySet(keyDst, TRUE); | ||
+ | } | ||
+ | else if (!noset) key_set(keyDst, FALSE); | ||
+ | } | ||
+ | |||
+ | void keySet(uint8 key, bool flag) { | ||
+ | if (key_get(key) != flag) { | ||
+ | key_set(key, flag); | ||
+ | } | ||
+ | } | ||
+ | </code> |
t2/gpc_scripting/usb_hid.1611484046.txt.gz · Last modified: 2021/01/24 05:27 by scachi