0
\$\begingroup\$

On Android, with Unity how do I get the status of caps lock, scroll lock and num lock LED's and blink these LEDs for caps lock, scroll lock and num lock from Unity 3D?

Blinking the LEDs will of course enable caps, num or scroll lock.

\$\endgroup\$
  • \$\begingroup\$ Any particular reason you feel the need to take over control of the user's device behind their back? As a casual user I would report that as a bug, "when I play XYZ my keyboard lights start flashing." Separately, you'll never be able to port this to IOS. Can you think of an internal way to handle what you need to do and not rely on subverting Unity? \$\endgroup\$ – Patrick Hughes Dec 22 '18 at 21:31
0
\$\begingroup\$

Unity3D's Input class has no function for firing a keypress, only reading it.

You'll need to find some other solution to emulate keypresses. Which on other platforms isn't all that easy ( Windows w/ user32.dll hook, MAC OSX (similar to Windows), Linux with xdotool ).

On Android these won't do (as while Android is Linux, it probably won't work with xdotool as there's no X windowing system). My proposal would be to use a Java program with this code and call it from the JNI from C#.

\$\endgroup\$
  • \$\begingroup\$ Unfortunately your answer does not answer the question for the platform android (tablet). I think if you wirte a java plugin (called from python of C sharp) in unity then this may solve the problem. But I dont know how to code this as I dont know Java. \$\endgroup\$ – qwerty10 Aug 31 '16 at 1:00
  • \$\begingroup\$ Yeah, I was under the impression that because Android was linux that you'd be able to use the xdotool but looking into it more that's probably not possible as it seems like every topic for this talks about the X windows system. See my updated answer \$\endgroup\$ – Coburn Sep 20 '16 at 21:43
  • 1
    \$\begingroup\$ According to the Android spec on keyboard driver requirements: "Keyboard drivers should support setting LED states when EV_LED is written to the device. The hid-input driver handles this automatically. At the time of this writing, Android uses LED_CAPSLOCK, LED_SCROLLLOCK, and LED_NUMLOCK. These LEDs only need to be supported when the keyboard actually has the associated indicator lights." Not a complete answer since it doesn't address how to write to EV_LED from Unity.. \$\endgroup\$ – Pikalek Feb 28 '17 at 17:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.