在服务的onkeydown? (全球热键) [英] onKeyDown in a service? (Global Hot Keys)

查看:172
本文介绍了在服务的onkeydown? (全球热键)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

谢谢!

推荐答案

您不能做到这一点:)

这篇关于在服务的onkeydown? (全球热键)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆