简体   繁体   English

定义组合键以在Android中执行操作

[英]Define key combination to perform an action in android

In android, how can I define a key combination in app to perform some action? 在android中,如何在应用中定义按键组合以执行某些操作?

For example, if user press e and x letters on a keyboard at the same time, how can I assign a special task to do when this event is fired? 例如,如果用户同时按下键盘上的ex字母,那么在触发此事件时如何分配特殊任务来执行?

You should know that any app you make will only capture 1 touch event at a time unless you utilize multi-touch. 您应该知道,除非您使用多点触控,否则您制作的任何应用一次只能捕获1个触控事件。 So first do this , here , this may help ,this was asked here before too. 因此,首先在这里这样做, 可能会有所帮助,这也是之前在这里提出的。

public boolean onTouchEvent(MotionEvent event) {
int x = (int)event.getX();
int y = (int)event.getY();
switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
    case MotionEvent.ACTION_MOVE:
    case MotionEvent.ACTION_UP:}
return false;}

From this you would get the postion of yout touch.Now do some logic on setOnClickListner of other button or "x" here. 由此,您将获得触摸的位置。现在,在此处对其他按钮或“ x”的setOnClickListner进行一些逻辑处理。

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM