pelya / android-keyboard-gadget

Convert your Android device into USB keyboard/mouse, control your PC from your Android device remotely, including BIOS/bootloader.
Apache License 2.0
1.22k stars 308 forks source link

add keystrokes for app #53

Closed Rosalie241 closed 8 years ago

Rosalie241 commented 8 years ago

hello @pelya I have a question: I am creating a hid app but I don't want to work with the hid-gadget-test file. Is it possible to build it into my app to send keystrokes from your hid patch?(I am using xamarin(mono for android/ C# for android) Regards, Tim

pelya commented 8 years ago

Yes, you just open /dev/hidg0 as a regular file, and write into it. Here's a piece of code that does this: https://github.com/pelya/android-keyboard-gadget/blob/master/hid-gadget-test/jni/hid-gadget-test.c#L178 The format of the bytes sent is described in readme: https://github.com/pelya/android-keyboard-gadget#how-it-works

Because of SELinux, Android app cannot open the file directly, so it launches su and pipes data through it, something like FILE *pipe = popen("su"); fprintf(pipe, "cat > /dev/hidg0\n"); then write keycodes to pipe, and don't forget to fflush().

On Sat, Jul 9, 2016 at 8:47 PM, Tim Wanders notifications@github.com wrote:

hello @pelya https://github.com/pelya I have a question: I am creating a hid app but I don't want to work with the hid-gadget-test file. Is it possible to build it into my app to send keystrokes from your hid patch?(I am using xamarin(mono for android/ C# for android) Regards, Tim

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/pelya/android-keyboard-gadget/issues/53, or mute the thread https://github.com/notifications/unsubscribe/AAJewKd9uhKq0uNx8UQuRH4aRrt07SHDks5qT967gaJpZM4JIqn9 .

Rosalie241 commented 8 years ago

If Selinux is diabled I can do someting like this right?: Echo 0x01 | /dev/hidg0

pelya commented 8 years ago

Yes you can. On Jul 9, 2016 10:34 PM, "Tim Wanders" notifications@github.com wrote:

If Selinux is diabled I can do someting like this right?: Echo 0x01 | /dev/hidg0

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/pelya/android-keyboard-gadget/issues/53#issuecomment-231551766, or mute the thread https://github.com/notifications/unsubscribe/AAJewNitXA72_Ezd_MBYq1aVjWTivFqnks5qT_e-gaJpZM4JIqn9 .

Rosalie241 commented 8 years ago

can you give me some more details about that " FILE *pipe = popen("su"); fprintf(pipe, "cat > /dev/hidg0\n"); then write keycodes to pipe, and don't forget to fflush()."? the command does not seems to work. ANd I am not understanding it.

pelya commented 8 years ago

It's a piece of C code, I don't know how are you doing file writing in C#. Open /dev/hidg0 and write into it chunks 8 bytes each, flush the buffer after each write, that's it. On Jul 10, 2016 8:56 AM, "Tim Wanders" notifications@github.com wrote:

can you give me some more details about that " FILE *pipe = popen("su"); fprintf(pipe, "cat > /dev/hidg0\n"); then write keycodes to pipe, and don't forget to fflush()."? the command does not seems to work. ANd I am not understanding it.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/pelya/android-keyboard-gadget/issues/53#issuecomment-231572448, or mute the thread https://github.com/notifications/unsubscribe/AAJewJp2BDllR5dQE8Oc_GF_58OSq6Crks5qUImWgaJpZM4JIqn9 .

Rosalie241 commented 8 years ago

if I create a test file(located on sdcard with: 0x0a in it) if I do a root shell and then: cat /sdcard/test > /dev/hidg0 but then it spams an random key from my keyboard, any idea?

Rosalie241 commented 8 years ago

or can you explain how to do it with the terminal? Because I can easilly send shell commands like cat in su.

pelya commented 8 years ago

Yes, you can copypaste a text file. Please read the keyboard protocol description at https://github.com/pelya/android-keyboard-gadget#how-it-works You send 8 bytes at once, not 1, and the first byte is special. On Jul 10, 2016 9:05 PM, "Tim Wanders" notifications@github.com wrote:

or can you explain how to do it with the terminal? Because I can easilly send shell commands like cat in su.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/pelya/android-keyboard-gadget/issues/53#issuecomment-231602324, or mute the thread https://github.com/notifications/unsubscribe/AAJewK4cWF6-mt9MO6QF81T0gufEWOHTks5qUTRQgaJpZM4JIqn9 .

Rosalie241 commented 8 years ago

I still don't understand it :-(

Rosalie241 commented 8 years ago

nevermind, I will use the hid-gadget test utillity :-)