#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <poll.h>
#include <signal.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#define SIGUER 980
int fd;
void my_signal_fun(int signum)
{
printf("my_signal_fun:signum=%d\n",signum);
}
int main(int argc, char *argv[]){
int keycode = 0;
int flags;
if(argc < 2){
printf("error:argc<2\n");
return 0;
}
sscanf(argv[1], "%d", &keycode);
fd = open("/dev/keydriver", O_RDWR);
printf("fd:%d\n",fd);
signal(SIGIO,my_signal_fun);
fcntl(fd,F_SETOWN,getpid());
printf("pid:%d\n",getpid());
flags=fcntl(fd,F_GETFL);
fcntl(fd,F_SETFL,flags|FASYNC);
printf("flags=%d\n",flags);
if(fd > 0){
printf("write keycode:%d\n",keycode);
write(fd, &keycode, sizeof(keycode));
}
if(fd > 0)
close(fd);
return 0;
}
Android.mk
LOCAL_PATH := $(call my-dir)
# HAL module implemenation, not prelinked and stored in
# hw/<HWCURSOR_HARDWARE_MODULE_ID>.<ro.product.board>.so
include $(CLEAR_VARS)
LOCAL_PRELINK_MODULE := false
LOCAL_MODULE_PATH := $(LOCAL_PATH)
LOCAL_SHARED_LIBRARIES := liblog libcutils
#LOCAL_SHARED_LIBRARIES := lpthread libcutils libc
LOCAL_SRC_FILES := testkey.c
LOCAL_MODULE := testkey
LOCAL_MODULE_TAGS := optional
#LOCAL_CFLAGS:= -DLOG_TAG="hwcursor"
include $(BUILD_EXECUTABLE)
./testkey 108
108为安卓系统的home键
键盘布局文件(*.kl)将完成第一步的转换,放在/system/usr/keylayout/下面
举例如下:
input.h 中字母键定义:
#define KEY_Q 16
#define KEY_W 17
#define KEY_E 18
#define KEY_R 19
#define KEY_T 20
#define KEY_Y 21
#define KEY_U 22
#define KEY_I 23
#define KEY_O 24
#define KEY_P 25