Native support for input devices | Native support for DIY input devices.



Rep: (1293)
This topic is a continuation of the article.//savagemessiahzine.com/2014/12/12/190359/
Here we discuss how to create native support for input devices and share ready-made solutions.
Attached Image

Tools
Tools:
  • Android 4+ device (checked only on 5.0 and 4.4);
  • USB OTG device support;
  • root access;
  • file manager with root support (in my case, this is Total Commander);
  • text editor (in my case it is Total Commander again);
  • a sheet of paper and a pencil;
  • USB Device Info(to determine the properties of the device);
  • Keytest(to display the device button codes)temporarily unavailable on the link, download from the forum link below.
    Another program that displays button codes and axis actionsGoogle play
    Universal program for testing buttons, editing actions and creating a configGamepad tester

Also, these applications can be downloaded on the forumNative support for input devices (Post # 36465278)

Step one. VID and PID
1. Creating a file with VID and PID
We connect our input device and launch the USB Device Info application. We are interested in the Linux tab, in which we select our device (I had it last in the list) and look for the values ​​of the Vendor ID and Product ID lines. In my case it was 0c45 and 7700, respectively.
Attached Image

Also VID and PID can be viewed by connecting the device to the PC.
Attached Image

For Bluetooth devices:
You can find these values ​​for Bluetooth devices by opening the file / proc / bus / input / devices.

Copy any file from / system / usr / keylayout to sdcard and rename it according to the received data; for my joystick, the name is:Vendor_0c45_Product_7700.kl. (Note that letter case does matter)

Step two. Getting button codes.
2. Getting Button Codes
Launch the KeyTest application and, armed with paper and a pencil, we start alternately pressing the buttons on the device, recording the numbers displayed after scanCode =. I wrote down the codes, placing them on paper, like buttons on a gamepad.
Attached Image
From the program you can exit only by the button "Home".

ATTENTION!
If Gamepad is visible in the first step, butKeytest does not respond on pressing, you may not have the required module in the kernel - say "thank you" to the author of the firmware.
But do not despair, there is a possible solution.Native support for input devices (Post wm-hater # 52134473)

Step three. Mapping buttons.
3. Mapping buttons
Now that the codes for all keys have become known, it is necessary to prescribe their functions. There are two ways:
a) find a device among the configs available in Android that is as close as possible to yours, and simply change the button codes in it by copying the contents to your file;
b) prescribe everything yourself.
I went the second way, because my joystick has only a control cross and four buttons. First you need to understand the syntax of the file layout, it is very simple:

key button code action_key

But then the question arose: what actions of the buttons to write in the config? For many years of using various gamepads on Android, I have determined for myself that the most universal config is the Sony Xperia Play layout, it behaves equally well in games and in the system interface.

Ok Google key mapping for Xperia Play

Key code constant scancode
X 23 KEYCODE_DPAD_CENTER 304
circle 4 KEYCODE_BACK 305
square 99 KEYCODE_BUTTON_X 307
triangle 100 KEYCODE_BUTTON_Y 308
up 19 KEYCODE_DPAD_UP 106
down 20 KEYCODE_DPAD_DOWN 105
left 21 KEYCODE_DPAD_LEFT 103
right 22 KEYCODE_DPAD_RIGHT 108
select 109 KEYCODE_BUTTON_SELECT 314
start 108 KEYCODE_BUTTON_START 28
L trigger 102 KEYCODE_BUTTON_L1 310
R trigger 103 KEYCODE_BUTTON_R1 311

We are interested in the third column, but the record of actions in it is slightly different from those that were found in the system - this is not an obstacle, just remove KEYCODE_.

I register my buttons (remember the sheet of pencil notes? It's time to find it ...):
!!! ATTENTION !!!
Need a text editor with support for unix encoding!
Notepad from Windows is NOT suitable,
Use, for example, Notepad ++
key 147 DPAD_CENTER
key 149 BUTTON_B
key 148 BUTTON_Y
key 146 BUTTON_X
key 157 DPAD_DOWN
key 145 DPAD_LEFT
key 155 DPAD_UP
key 156 DPAD_RIGHT

But here it was not without nuances. At Sony, the KEYCODE_BACK action (the “back” button, which is familiar to us, is assigned to the “circle” button). It is easy to guess that pressing such a button in the game can cause a nervous breakdown. And the thing is that during the game on Xplay, this button takes an alternative value - KEYCODE_BUTTON_B. Here we prescribe it.
The offset along the axis is written as:
axis 0x00 HAT_X
axis 0x01 HAT_Y


Step Four. The moment of truth.
4. The moment of truth
Save our file and copy it to the / system / usr / keylayout folder. Set rights -rw -r -r (644). We reboot the device (I didn’t do this myself, just blocked and unlocked, but for the purity of conscience and experiment I had to write it).

We connect our device, and if everything is done correctly, then you can immediately use the “crossbar” to navigate the Android menu. The button assigned to DPAD_CENTER will be the select button, and BUTTON_B the back button.


Problems and possible solutions
Q:I prescribe everything correctly, but the config does not cling.
BUT: If you register action codes with an error, for example:
key 123BUTTON_HOMEinstead of key 123HOME
then the system will consider this file erroneous.
The best way to check if your kl file is picked up by the system or not is to erase all keycodes or comment them out with a # sign:
#key 123 BUTTON_HOME
If the file is picked up - there will be no reaction to the buttons, but everything will be displayed in KeyTest.

Q:I prescribe everything correctly and without errors, but all or part of the buttons do not work.
BUT: Try writing scancode in hex format: Native support for input devices (Post romanctest # 69194647)
Q:Dualshok 4 constantly falls off or works with a delay.
BUT: Native support for input devices (Post maxmergov # 81264882)

Useful links:

Video instruction if the letters are tight.

Ready * .kl files

Cap in design mode.

Post has been editedderak1129 - 26.01.20, 20:39
Reason for editing: Editing.



Rep: (0)
I have a wamo g910 gamepad, lg g pro works fine, even mapping is not necessary, but on zenfone 6 it just connects, is defined as a keyboard, but does not work and does not appear in / proc / bus / input / devices. What could be the problem? Different bluetooth processor stacks?



Rep: (1293)
Genius Maxfire G12 Wireles
Picture
Attached Image

Attached fileGenius Maxfire G12 Wireles.zip(647 bytes)


Post has been editedDreamer ... - 13.12.14, 22:23



Rep: (1293)
Thrustmaster LightBack is determined by USBDeviceinfo, but there is no response to key tests in Key Test
Try to create an empty kl file. Added this info to the header.

and on zenfone 6 it simply connects, is defined as a keyboard, but does not work and does not appear in / proc / bus / input / devices.
If it is defined as a keyboard, it must be registered somewhere. Try to look by connecting to lg g pro or to a PC.



Rep: (3)
And the finished file for dualshock 3 is not no one lying around?



Rep: (24)
Dreamer ... 12/13/2014, 21:11*
Well, the keikods may not be the same.


And how to do?



Rep: (1293)
* Shadow326159 read the header and see which codes Joy gives out and which ones are written in the kl file.
* Alexan374, It is built into the system, connect via USB, press the central button - play.



Rep: (1)
* Dreamer ...,
tell me, I reassigned my joey to Sony Playstation (R) 3 Controller, checked it with keytest, everything is OK
I go to gta sa, only the turn and acceleration / brake work, where to dig?

Post has been editedlnsurgent - 14.12.14, 17:14



Rep: (24)
* Dreamer ...,
I can not get the button codes because without usb / bt joystick center, the gamepad does not work at all.



Rep: (1293)
* lnsurgent
Rename the file to txt and attach it to the message.
Well, in the GTA settings look, for a start. In III and VS, everything worked fine.
* Shadow326159 Strange, since the program sees it and the android should see.
UPD
I found a Chinese clone dualshock3 among my joysticks.
Sixaxis controller connects and works via bluetooth, and sees USB device info through the USB cable, VID and PID are the same as the original, dsmsg also sees it in the terminal, it even shows the battery charge. But button presses are not visible, neither in keyTest, nor in other similar programs, on commandshowkey -asilence in the terminal too.There is a suspicion thatI checked on the PC, Joy does not work at all via USB, only bluetooth.

Post has been editedDreamer ... - 14.12.14, 21:00



Rep: (1)
Attached fileiGamate.txt(382 bytes)
But how to look at the settings of joey in gta sa itself?
Dreamer ... 12/14/2014, 16:34*
I found a Chinese clone dualshock3 among my joysticks.
Sixaxis controller connects and works via bluetooth, and sees USB device info through the USB cable, VID and PID are the same as the original, dsmsg also sees it in the terminal, it even shows the battery charge. But button presses are not visible, neither in keyTest, nor in other similar programs, by the showkey -a command in the terminal, silence is also. There is a suspicion that Checked on a PC, Joy does not work at all via USB, only bluetooth.
by usb they only charge



Rep: (12)
Here is a completely correct and accurate file variant for EXEQ NEONLight

Attached files

Attached fileEXEQ + NEONLight.zip(534 bytes)



Rep: (3)
* Alexan374, It is built into the system, connect via USB, press the central button - play.

I understood this, but what about the wireless connection? All the same, the wire is not very convenient, I connect my Dual Shock 3 through the Sixaxis Controller program. And here I want the details with the reassignment of buttons, since in a good half of the games (excluding emulators) the desired configuration is not set or the game does not have any use at all .



Rep: (1293)
* bati7, make a template, please.
* Alexan374, deal with the program sixaxis - in it you can customize the value of the buttons, native support and emulation of clicks.
by usb they only charge

And no. The original is both on Android and on the PC, and on the Mac quietly works via USB, but the Chinese clone did not want to ...



Rep: (1293)
* lnsurgent Very strange button codes for you, or rather their spread. According to my observations, they go in order, and here the range is from 1 to 100+
Check on another game. Or on the ppsspp emulator, if everything is set up correctly, then he will pick up the control himself.



Rep: (11)
Guys, and I have a cross code of all the buttons showing 0. How to be?



Rep: (1293)
* maNN_23, Is this not an analog stick?
Try to register as for analog.



Rep: (11)
Dreamer ..., yes, I figured it out, it copies the stick, it worked through the axis) only games refuse to respond adequately to the layout, such as: asphalt 8 shoved the gas button on the right upper shift



Rep: (1293)
* maNN_23, Shifty gas - the norm for racing. But the same Beach Baggie Blitz allows mappit buttons in the settings, so there’s a question for developers. But you can correct the layout for a specific game.



Rep: (11)
Dreamer ..., already gash on the cross, thanks)
Here are the Keys for my Chinese

Denn DGP231W / B
Picture


Attached files

Attached fileVendor_0810_Product_0003.txt(974 bytes)



Rep: (1293)
* maNN_23, This config with R1 on the "cross"?


Full version    

Help     rules

Time is now: 18/07/20, 00:59