Capture all Ctrl-? under Android

百般思念 提交于 2020-01-05 07:12:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!