问题
I'm modifying ConnectBot to take advantage of hardware keyboards and I need to capture all Ctrl-? presses. I've disabled all of the alphabetic menu shortcuts (such as Ctrl-C for copy) but the key presses still don't seem to be being received by the onKey event.
I'm fairly new to Android development (literally started today to fix ConnectBot to handle hardware keyboards) and quick Google searching doesn't seem to turn up anything about capturing Ctrl-? key presses.
How do I tell Android to pass these straight through to the onKey handler?
回答1:
It turns out that the keyCode was set to the correct character value (e.g. 'C'). However, the result of getUnicodeChar() was 0 because CTRL was being held.
All that was needed was to add handling to get the unicode character regardless of the meta-keys that are being held down with:
if (event.isCtrlPressed())
event = new KeyEvent(KeyEvent.ACTION_DOWN, keyCode);
Then later on it was necessary to encode the "CTRL is being held down" information in the key data that was being sent, which was already functionality provided by the ConnectBot code.
来源:https://stackoverflow.com/questions/12337117/capture-all-ctrl-under-android