66import org .netdex .androidusbscript .function .DeviceStream ;
77import org .netdex .androidusbscript .util .FileSystem ;
88import org .netdex .androidusbscript .function .HidInput .Keyboard .Mod ;
9+ import org .netdex .androidusbscript .util .Util ;
910
1011import static org .luaj .vm2 .LuaValue .NONE ;
1112import static org .netdex .androidusbscript .MainActivity .TAG ;
@@ -36,7 +37,7 @@ public LuaHidKeyboard(FileSystem fs, String devicePath) throws IOException {
3637 *
3738 * @param keys HID keyboard bytes
3839 */
39- public void raw (byte ... keys ) throws IOException , InterruptedException {
40+ private void raw (byte ... keys ) throws IOException , InterruptedException {
4041 byte [] buffer = new byte [8 ];
4142 if (keys .length > 7 )
4243 throw new IllegalArgumentException ("Too many parameters in HID report" );
@@ -45,15 +46,31 @@ public void raw(byte... keys) throws IOException, InterruptedException {
4546 this .write (buffer );
4647 }
4748
48- public void press (byte ... keys ) throws IOException , InterruptedException {
49- raw (keys );
50- raw ();
51- }
49+ public static VarArgFunction press = new VarArgFunction () {
50+ @ Override
51+ public Varargs invoke (Varargs args ) {
52+ args .argcheck (args .narg () >= 2 , 0 , "at least 2 args required" );
53+ LuaHidKeyboard hid = (LuaHidKeyboard ) args .arg1 ().checkuserdata ();
54+
55+ byte [] a = new byte [args .narg ()];
56+ a [0 ] = MOD_NONE .code ;
57+ for (int i = 2 ; i <= args .narg (); ++i ) {
58+ a [i - 1 ] = checkbyte (args .arg (i ).checkint ());
59+ }
60+ try {
61+ hid .raw (a );
62+ hid .raw ();
63+ } catch (IOException | InterruptedException e ) {
64+ throw new LuaError (e );
65+ }
66+ return NONE ;
67+ }
68+ };
5269
5370 public static VarArgFunction chord = new VarArgFunction () {
5471 @ Override
5572 public Varargs invoke (Varargs args ) {
56- args .argcheck (args .narg () >= 3 , 0 , "at least 2 args required" );
73+ args .argcheck (args .narg () >= 3 , 0 , "at least 3 args required" );
5774 LuaHidKeyboard hid = (LuaHidKeyboard ) args .arg1 ().checkuserdata ();
5875
5976 byte mask ;
@@ -73,7 +90,8 @@ public Varargs invoke(Varargs args) {
7390 a [i - 1 ] = checkbyte (args .arg (i ).checkint ());
7491 }
7592 try {
76- hid .press (a );
93+ hid .raw (a );
94+ hid .raw ();
7795 } catch (IOException | InterruptedException e ) {
7896 throw new LuaError (e );
7997 }
0 commit comments