在Android的模拟键盘事件 [英] Simulating Keyboard Events in Android

查看:183
本文介绍了在Android的模拟键盘事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,我试图解雇键盘事件。我现在用的仪器仪表类,它是在模拟器上可以正常使用,但是当我启动我的装置,呼叫不能正常工作,有没有什么办法让它工作吗?

I have a project and I am trying to fire Keyboard events. I am using the Instrumentation Class, and it is working perfectly on the emulator, but when I launch it on my device, the call doesn't work, is there any way to make it work?

另外,我在网上搜索时,我发现关于IWindowManager和内部API的一些帖子,我完全理解使用它们的风险,但我的项目是一家集科研,不适合公布,所以我不介意用我的,项目这些API,如果他们能解决我的问题,但问题是,我无法找到包含这些类的JAR。

Also, I searched on the web, and I found some posts about the IWindowManager and the internal APIs, I fully understand the risk of using them, but my project is a research and is not intended to be published, so I don't mind using those APIs in my porject if they can solve my problem, but the problem is that I can't find the JAR that contains these classes.

TLDR:我需要一个解决方案,可以帮助我火键盘事件我的Andr​​oid设备上,任何想法都pciated AP $ P $

TLDR : I need a solution that helps me fire keyboard events on my Android device, any ideas are appreciated

推荐答案

其实,还有一个更简单的方法,我发现
使用Activity类或类网页视图。都具有相同的功能。
在code看起来是这样的:

Actually, there is an easier method, that I found Using Activity class or WebView class. Both have the same function. The code looks something like this:

webView.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_1));

这篇关于在Android的模拟键盘事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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