Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rog Ally back paddles mapping #1088

Closed
Meeohx opened this issue Aug 15, 2023 · 39 comments
Closed

Rog Ally back paddles mapping #1088

Meeohx opened this issue Aug 15, 2023 · 39 comments
Labels
help wanted Extra attention is needed on-hold would like to implement, but can't cause there is no info yet

Comments

@Meeohx
Copy link

Meeohx commented Aug 15, 2023

Can the back paddles of ROG Ally be somehow separately mapped like in AC?

@seerge
Copy link
Owner

seerge commented Aug 15, 2023

@Cheng77777 hello, they produce same key code, so most probably - no :)

@Meeohx
Copy link
Author

Meeohx commented Aug 15, 2023

Courious how AC implement separate key mappings

@seerge
Copy link
Owner

seerge commented Aug 15, 2023

@Cheng77777 i have a feeling it binds it somehow on hardware level, i.e. pedals just start physically emitting a new key codes.

It’s probably some usb command that tells controller to do so. But since i have returned my Ally back to store i can’t really investigate that :)

@Meeohx
Copy link
Author

Meeohx commented Aug 15, 2023

well, it makes sense to me, wanted to test the key code myself but I did not find the propper tool lol.

@seerge
Copy link
Owner

seerge commented Aug 15, 2023

@Cheng77777 You can download https://www.hhdsoftware.com/device-monitoring-studio and then intercept all USB traffic between your controller (it's a USB device) and armoury for example

Most probably the moment you set a specific binding in AC it would send some payload to the device telling to do that

@seerge seerge added the on-hold would like to implement, but can't cause there is no info yet label Aug 15, 2023
@ggrensteiner
Copy link

Do you guys have an Ally to test this with? There's been some research on the linux side for the keycode mapping and it appears like there's a hardware default for the back keys to be a sticky keys switch on single button press and release on pressing both of them.

From what I can tell there's three modes switched between in AC with the most ideal one being M1 and M2 split into their own functions. It would be great if you had an option to set up the keybindings with a default of Armory Crate key mapped to Guide, Control Center function set to CTRL2 and the back buttons set to standard keysyms that are unbound.

Mostly I think it would be great for someone with proper tools to capture the configuration method out of AC to put the controller into a coherent mode since nobody seems to be able to figure it out; and you guys seem to have the most experience with ASUSs braindead hardware configuration methods.

@seerge seerge added the help wanted Extra attention is needed label Aug 31, 2023
@ggrensteiner
Copy link

Here's the init to map the back panels to a real event of ctrl F9 and ctrl F10. Also attached is the pcap and some notes. I hope this gets us a good init in your wonderful software.
splitback.zip

@seerge
Copy link
Owner

seerge commented Sep 9, 2023

@ggrensteiner hello, thanks. I have returned my Ally back to store, so can't really debug / test it unfortunately :)

I was trying to understand your payloads

5ad102082c0400000000028c0900000000000000000000000000000400000000028c010000000000000000000000000000000000000000000000000000000000

028c09 and 028c01seem to be bindings :) but i don't know real structure,

I think it would be cool to capture more data (i.e. set different bidings, probably simple one-keys as well and try to decypher meaning of each byte)

@ggrensteiner
Copy link

And a config package to go to mouse mode, and other to go back to poweron default
configscripts.zip

@ggrensteiner
Copy link

This is a config payload that loads a bunch of memory space on the N-Key device that's pretending to be a keyboard, mouse and xbox controller. It changes the keysyms coming out of the device completely. I can do a compare of what they were before to what they become next weekend if you like.

@Valkirie
Copy link

Valkirie commented Oct 3, 2023

Did you guys make any progresses here? I have too much on my plate already to focus on the Ally alone.

@seerge
Copy link
Owner

seerge commented Oct 5, 2023

@Valkirie nope, I don't have Ally at the moment :) so it's effectively unrealistic to debug that USB-protocol that sets bindings

@IceStormNG
Copy link
Contributor

@Valkirie nope, I don't have Ally at the moment :) so it's effectively unrealistic to debug that USB-protocol that sets bindings

I do have an ally since a few days.... May I help with the USB debugging? What do you need?

@seerge
Copy link
Owner

seerge commented Oct 7, 2023

@IceStormNG pretty much the same you did for mouse protocol.

Set backpedal buttons to emit certain keys in AC, and intercept USB packet with command

Apparently those buttons can be programmed to emit (any?)key on hardware level via special usb payload

@IceStormNG
Copy link
Contributor

I will have a look at later.

@IceStormNG
Copy link
Contributor

Ok. It looks like I found the packet. Only problem is: I cannot make any rhyme out of the codes they send for the key setting. It is not the HID keycode.

This sets both Macro keys to F11. HID keycode for F11 is 0x44

5A D1 02 08 2C 02 00 [78] 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 02 00 [78] 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

This sets M1 to A and M2 to B (keyboard). HID Keycodes for A is 0x04 and for B 0x05.

5A D1 02 08 2C 02 00 [32] 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 02 00 [1C] 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

This sets M1 to C and M2 to B (keyboard). HID Keycodes for C is 0x05 and for B 0x05.

5A D1 02 08 2C 02 00 [32] 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 02 00 [21] 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

It looks like the second marked byte is M1 and the first is M2

This sets M1 to 'Take screenshot' and M2 to B (keyboard).

5A D1 02 08 2C [02] 00 [32 00] 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 [05] 00 [00 16] 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

Looks like "2" is for "Keyboard key" and 5 for "Action". It also looks like the keycode is 2 bytes.

This sets M1 to 'Take screenshot' and M2 to X (Controller).

5A D1 02 08 2C [01] [03 00 00] 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 [05] [00 00 16] 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

Hm.. maybe it's 3 bytes for the keycode? Or the first is for "Controller" ,second for "Keyboard" and 3rd for "Special stuff"

This sets M1 to 'Left Mouse' and M2 to X (Controller).

5A D1 02 08 2C [01] [03 00 00 00] 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 [03] [00 00 00 01]
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

Make it 4 byte while we're at it. 4th byte seems for mouse actions. WTF ASUS

This sets M1 to 'Left Mouse' and M2 to 'CTRL + ALT + ESC' .

5A D1 02 08 2C [04] [00 00 00 00 03 8C 8A 76] 00 00
00 00 00 00 00 00 00 00 00 00 00 [03] [00 00 00 01]
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

Urm..... For real? Alright we can use up to 5 keys in macros

This sets M1 to 'Left Mouse' and M2 to 'A S U C K' . (lmao)

5A D1 02 08 2C [04] [00 00 00 00 05 1C 1B 3C 21 42]
00 00 00 00 00 00 00 00 00 00 00 [03] [00 00 00 01]
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

That's enough ASUS BS for today.

@seerge
Copy link
Owner

seerge commented Oct 7, 2023

@IceStormNG actually this is already good! Main problem here was that both backpedals produced same keycode, as far they produce different ones - that would be enough for G-Helper to listen (i.e. register global hotkeys) and process them accordingly

This is very similar to how M1/M2 buttons work on laptop (they emit hardware volume up / down keys). I assume you can also make them emit something else on hardware level (via AC), but in app - i just listen to volume keys directly
https://github.com/seerge/g-helper/blob/1968b6487c062d1068f509330d20d60fcee1363c/app/Input/InputDispatcher.cs#L126C22-L126C22

@IceStormNG
Copy link
Contributor

IceStormNG commented Oct 7, 2023

So, you plan to set them to something specific, then just use GHelper to handle the hotkeys instead of making a tool to configure them on hardware level?

These are the USB Payloads to set the M1/M2 keys. They do emit the correct keycode (not the one that we sent, but the equivalent one) on the HID Keyboard device.

@IceStormNG
Copy link
Contributor

They produce the same keycodes by default, because, out-of-the-box, they're both configured to "Secondary Function" and. So you would have to set them to something different before, then they also become different. I'm not sure though, whether the Ally saves the keycodes in hardware permanently or whether they have to be re-set after a powercycle.

@seerge
Copy link
Owner

seerge commented Oct 7, 2023

@IceStormNG well, sounds like it will be easier (or at least understandable). Just bind M2 to something non-default (like emit F23), and then process F23 as hotkey.

Only trouble here - that i don't know how to emit non-keyboard actions (like gamepad X or start, or so), but this applies to all bindings not only backpedals :)

Alternative - is to literally build a table of codes for each key ... :|

@IceStormNG
Copy link
Contributor

We could build a table for the controller and mouse keys, and do the keyboard stuff in software. The Controller keys are limited. But I'm not going to test out all 102+ Keyboard keys with AC and a USB packet logger because ASUS just couldn't use the HID codes.

@IceStormNG
Copy link
Contributor

Just bind M2 to something non-default (like emit F23), and then process F23 as hotkey.

Yeah.. that will not work. AC won't let you pick such a key. So I cannot tell you what code we would have to send to do that.

@seerge
Copy link
Owner

seerge commented Oct 7, 2023

@IceStormNG yeah, i would say just separate M2 to something else first :) that will be already a big step. I wonder if it's possible to set it to emit a HID keycode as it does by default ,but different one (not 165)

https://github.com/seerge/g-helper/blob/1968b6487c062d1068f509330d20d60fcee1363c/app/Input/InputDispatcher.cs#L531C26-L531C29

@seerge
Copy link
Owner

seerge commented Oct 7, 2023

@IceStormNG btw, i'm sure that even on laptops Asus uses same approach for binding M-keys (i.e. they start emitting something else on hardware level). I just didn't bother decoding it in a first place, as just listening to original keycodes and processing them is way easier.

@IceStormNG
Copy link
Contributor

ARMOURY CRATE SE 07 10 2023 19_27_22

For keyboard, we have those as options. And I don't think we should abuse any of those.

@seerge
Copy link
Owner

seerge commented Oct 7, 2023

@IceStormNG there are a lot of exotic keys in windows that can be used
https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes

@IceStormNG
Copy link
Contributor

Yes, but we do not know the ASUS keycodes for that.

@IceStormNG
Copy link
Contributor

IceStormNG commented Oct 7, 2023

To Program the M2 key to such a key, you need to send the keycode, but ASUS does not use the HID keycodes to configure the device. They use a different code to send over to the Ally, then emit the "correct" code via the HID keyboard.

Idk whether there is any correlation between the HID codes and the ASUS codes or whether ASUS just made their own table.

@seerge
Copy link
Owner

seerge commented Oct 7, 2023

@IceStormNG i know, but i mean that it's possible to pick something even more exotic than F23

Key-combo can also work

@IceStormNG
Copy link
Contributor

Otherwise, we would just need a table to map ASUS -> HID and we could just programm the damn thing in hardware.

@IceStormNG
Copy link
Contributor

Though here comes another issue. ASUS uses a non HID transfer function to send the data to the Ally. So... we would also kinda need some way to send the data in the same way.

@IceStormNG
Copy link
Contributor

Alright. I really did it and fully decoded the back pedal mapping protocol with all keys that AC supports.

Endpoint is the ASUS Device VID: 0xB05 PID: 0x1ABE, Interface Index 2
Packet length 0x40(64) Bytes
Protocol is "Class Specific Request" (usb_function_class_interface). Means it is not a standard HID function so it seems like it is some driver specific function. I have no idea how to send that so that the device interprets it correctly.

5A D1 02 08 2C 
[00] [00 00 00 00 00 00 00 00 00 00] M2 Primary
[00] [00 00 00 00 00 00 00 00 00 00] M2 Secondary
[03] [00 00 00 00 00 00 00 00 00 00] M1 Primary
[00] [00 00 00 00 00 00 00 00 00 00] M1 Secondary

[00            00          00        00       00 00 00 00 00 00] 
 ^Controller   ^Keyboard   ^Action   ^Mouse   ^Macro (1 code per byte, unused bytes are 0x00)


Save comfig: 5A D1 0A 01

Mode

00 = Disabled
01 = Controller
02 = Keyboard
03 = Mouse
04 = Macro (Up to 5 keyboard codes)
05 = Action


Default = Use Secondary
5A D1 02 08 2C 
[02] [00 8E 00 00 00 00 00 00 00 00] M2 Primary
[02] [00 8E 00 00 00 00 00 00 00 00] M2 Secondary
[02] [00 8F 00 00 00 00 00 00 00 00] M1 Primary
[02] [00 8F 00 00 00 00 00 00 00 00] M1 Secondary


Keycodes

Keyboard (Mode 0x02)

A = 0x1C
B = 0x32
C = 0x21
D = 0x23
E = 0x24
F = 0x2B
G = 0x34
H = 0x33
I = 0x43
J = 0x3B
K = 0x42
L = 0x4B
M = 0x3A
N = 0x31
O = 0x44
P = 0x4D
Q = 0x15
R = 0x2D
S = 0x1B
T = 0x2C
U = 0x3C
V = 0x2A
W = 0x1D
X = 0x22
Y = 0x35
Z = 0x1A

1 = 0x16
2 = 0x1E
3 = 0x26
4 = 0x25
5 = 0x2E
6 = 0x36
7 = 0x3D
8 = 0x3E
9 = 0x46
0 = 0x45


F1 = 0x05
F2 = 0x06
F3 = 0x04
F4 = 0x0C
F5 = 0x03
F6 = 0x0B
F7 = 0x80
F8 = 0x0A
F9 = 0x01
F10= 0x09
F11= 0x78
F12= 0x07


ESC= 0x76
^  = 0x0E
-  = 0x4E
=  = 0x55

BCK= 0x66
ENT= 0x5A
SPC= 0x29
TAB= 0x0D

RSH= 0x89
LSH= 0x88
LAL= 0x8A
RAL= 0x8B

RCT= 0x8D
LCT= 0x8C
CLK= 0x58
WIN= 0xB2

.  = 0x49
,  = 0x41
/  = 0x4A
\  = 0x5D



Gamepad (Mode 0x01)

LB = 0x05
LT = 0x06
L3 = 0x07
R3 = 0x08

A  = 0x01
B  = 0x02
X  = 0x03
Y  = 0x04

UP = 0x09
DWN= 0x0A
RGT= 0x0C
LFT= 0x0B

MEN= 0x12
VIW= 0x11



Mouse (Mode 0x03)

L  = 0x01
R  = 0x02
SCD= 0x04
SCU= 0x05
SCC= 0x03


Action (Mode 0x05) : Might require Armoury Crate Service to work

Screenshot    = 0x16
Show Keyboard = 0x19
Task Manager  = 0x04
Show Desktop  = 0x1C
Microphone off= 0x01
Volume up     = 0x03
Volume down   = 0x02
Xbox Key      = 0x13

@seerge
Copy link
Owner

seerge commented Oct 8, 2023

@IceStormNG great! Amazing job and a very impressive research.

Looking at the codes - seems like Asus used completely custom protocol for that!

So the only thing missing is how to mark usb-packet as Class Specific Request ? I will try to check what AC sends to asus keyboards on laptops for macro keys, and will try to replicate at least that part ...

@Valkirie
Copy link

Valkirie commented Oct 8, 2023

@IceStormNG great! Amazing job and a very impressive research.

Looking at the codes - seems like Asus used completely custom protocol for that!

So the only thing missing is how to mark usb-packet as Class Specific Request ? I will try to check what AC sends to asus keyboards on laptops for macro keys, and will try to replicate at least that part ...

Very well documented work indeed. Eager to see if you guys succeed here.

@CasperH2O
Copy link

@IceStormNG @seerge , from the packages that @ggrensteiner shared with the Handheld Companion team here: Valkirie/HandheldCompanion#671 (comment) I was able to determine that this package should set the back buttons to work as F17 and F18?

5ad1 02082c 020028 00000000000000000000000000000000000000 020030 0000000000000000 000000 0000000000000000000000000000000000000000000000

I have an ROG Ally, but I am very unfamiliar with HID packages, is there some tool or C# library I could (ab)use to send this to the correct HID device to see what happens?

@CasperH2O
Copy link

Just a small update from my side, I have (within the HC application) a working prototype where I send the all the HID commands. I'm not there yet though.

If I first set the gamepad to default with backpaddles to something like F1 and F2 using Armoury Crate, then close all of that and run my commands from HC, the gamepad is default and both back paddles return F17. The command I'm sending was confirmed to work to make them F17 and F18 under ChimeraOS so I must be doing something wrong.

I'll be double checking and comparing the full command I'm sending and perhaps try some timeouts or something. Will continue shortly.

@seerge
Copy link
Owner

seerge commented Jan 17, 2024

@ggrensteiner @Cheng77777

I have released a first preview of custom bindings for a whole controller https://github.com/seerge/g-helper/releases/tag/v0.148

This also covers M1/M2 buttons obviously :)

Thanks for the research to @IceStormNG

@seerge
Copy link
Owner

seerge commented Jan 17, 2024

P.S. It's still not polished visually as I have some better ideas for UI

Bindings work only when you select Gamepad controller more (or if you have it on Auto and it is gamepad stage, i.e. in game)

@seerge
Copy link
Owner

seerge commented Jan 23, 2024

Closing as completed now :)

@seerge seerge closed this as completed Jan 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed on-hold would like to implement, but can't cause there is no info yet
Projects
None yet
Development

No branches or pull requests

6 participants