在服务的onkeydown? (全球热键)热键、全球、onkeydown

2023-09-12 06:21:02 作者:八百逗比奔北啵!

什么我基本上是试图实现的是自定义全局热键或者换句话说,'事情时,我把某些按钮无论哪个方案目前在上面会发生。 我认为服务是必要的。

What I'm basically trying to achieve is custom global hot keys or in other words 'things will happen when I push certain buttons no matter which program is currently on top'. I assume a service is needed.

我有一个快速和肮脏的测试,只是告诉我什么一直是pressed,将工作,如果它是活动窗口。

I have a quick and dirty test that just tells me what has been pressed that will work if it is the active window.

public boolean onKeyDown(int keyCode, KeyEvent event) {
    char pop;
    pop = (char)event.getUnicodeChar();
    Toast.makeText(this, Character.toString(pop) , Toast.LENGTH_SHORT).show();
    return super.onKeyDown(keyCode, event);
  }

但很明显,如果我改变窗口或进入一个文本框它不工作。如果我直接将其放入一个服务(或imputmethodservice),并推出上述服务,没有任何反应。 (需要某些权限可能?) 任何建议我要去哪里错了?或捕获该按钮的一个更好的办法是pressed?

But obviously if I change window or go into a text box it doesn't work. If I stick it directly into a service (or an imputmethodservice) and launch said service nothing happens. (Some permissions required maybe?) Any suggestions where I'm going wrong? Or a better way of capturing which button is pressed?

谢谢!

推荐答案

您不能做到这一点:)