android模拟触控power键
来源:互联网 发布:软件为什么需要预约 编辑:程序博客网 时间:2024/06/06 18:36
之前一个项目上遇到一个问题是在特定的代码执行完毕后需要实现一个唤醒的动作,虽然这个问题后续没有用到休眠唤醒的动作,但是后续闲暇时间却针对这个问题来研究了一下。因为我们按下然后弹起power键实际上是可以实现休眠唤醒的,那就模拟按下和弹起的动作,主要就是上报KEY_POWER这个键值。
根据输入子系统的研究,上报键值需要依赖一定的输入设备,在无线程可用的输入设备的时候,只能自己注册一个输入设备。
#include <linux/input.h>#include<linux/init.h>#include<linux/module.h>#include<linux/kernel.h>#include <linux/proc_fs.h>#include<linux/uaccess.h> static struct input_dev *my_dev;static struct proc_dir_entry *my_proc;static ssize_t write_proc(struct file *file,const char *buffer, size_t count, loff_t *ppos){int my_status = 0;int num = 0; char temp[50]; // for store special format cmd if (copy_from_user(temp, buffer, sizeof(temp))){ return -EFAULT; }num = sscanf(temp,"%d",&my_status);if(num==1){input_report_key(my_dev, KEY_POWER, 1);input_sync(my_dev);input_report_key(my_dev, KEY_POWER, 0);input_sync(my_dev);}return sizeof(temp);// 返回0会不停的亮灭屏}static const struct file_operations test_proc = {.write = write_proc,};static int test_init(void){int err = 0;my_dev = input_allocate_device();my_dev->name = "feifei_dev";input_set_capability(my_dev, EV_KEY, KEY_POWER);err = input_register_device(my_dev);if(err<0){printk(" failed to register my input_dev\n");}my_proc = proc_create("feifei_proc", 0666, NULL, &test_proc);return 0;}static void test_exit(void){return;}module_init(test_init);module_exit(test_exit);MODULE_LICENSE("GPL");
阅读全文
0 0
- android模拟触控power键
- android power键流程
- HDU6034-Balala Power-模拟
- Balala Power! (模拟)
- iOS代码模拟Home+power键实现截屏
- 模拟Android多点触控
- 添加模拟power key 动作
- Android 屏蔽Power键 Home键
- Android 屏蔽Power键 Home键
- android长按power键自动关机定制
- Android开发中 如何处理power键
- Android 按power键唤醒屏幕流程
- Android平台Power键处理机制
- Android 按power键唤醒屏幕流程
- Android Framework层Power键关机流程
- Android Framework层Power键关机流程
- Android Framework层Power键关机流程(一,Power长按键操作处理)
- android模拟back键
- 删除 IDEA 的所有设置,缓存,插件和log
- 超简单仿QQ步数显示控件
- nodejs--promise之bluebird部分API
- 碎片实现多个页签切换
- Android 添加Library出现错误Error:(2, 0) Plugin with id 'com.github.dcendents.android-maven' not found.
- android模拟触控power键
- 10个让设计简单干净的黄金法则
- 论敏捷开发的优缺点
- LifeRay的portlet开发(使用Eclipse)- 想说Hello不容易!
- Servlet与jsp的通信
- webservice Client 生成
- iOS中UIWebView与WKWebView、JavaScript与OC交互、Cookie管理看我就够(下)
- javascript学习笔记(一)
- [RK3288][Android6.0] MediaCodec的configure配置过程小结