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\$
1
  • \$\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\$ Commented Dec 22, 2018 at 21:31

1 Answer 1

1
\$\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\$
3
  • \$\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
    Commented Aug 31, 2016 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\$
    – Cobertos
    Commented Sep 20, 2016 at 21:43
  • 2
    \$\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
    Commented Feb 28, 2017 at 17:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .