I can now write a simulated keys and touch events on different android applications, but with sendPointerSync and sendKeySync can not be used in different processes, there will be a use Injecting to another application requires INJECT_EVENTS permission exception. Even added a INJECT_EVENTS authority is not enough, so do the underlying JNI to write a simulation. Which heroes know how to do it? best to give code. greatly appreciated!!!!!!!!
Reply:
Take a look monkey bar code, in development / cmds / monkey / src / com / android / commands / monkey. Inputmanager Laigao through the inside. I do not know whether it is something you want, right when puts it
Reply:
With sendevent command like, if you have the patience, you can also put it into the JNI
Reply:
Oh I see next.
Reply:
< br />
sendevent command to how to use? there in which you can find its source.
Reply:
sendevent / dev / input / eventX X X X
http://blog.csdn.net/watson243671/article/details/6647334
Reply:
The emergence of new problems.
I now some development board, the screen is
800 * 480 ofBut I used the top left corner getevent, and the touch screen to the data as follows:
/ Dev/input/event1: 0003 0000 0000005b
/ Dev/input/event1: 0003 0001 000000f1
/ Dev/input/event1: 0001 014a 00000001
/ Dev/input/event1: 0000 0000 00000000
/ Dev/input/event1: 0003 0000 0000005f
/ Dev/input/event1: 0000 0000 00000000
/ Dev/input/event1: 0003 0000 00000061
/ Dev/input/event1: 0000 0000 00000000
/ Dev/input/event1: 0003 0000 00000066
/ Dev/input/event1: 0000 0000 00000000
/ Dev/input/event1: 0003 0000 000002e9
/ Dev/input/event1: 0003 0001 0000391f
/ Dev/input/event1: 0001 014a 00000000
/ Dev/input/event1: 0000 0000 00000000
Lower right corner of the touch screen and the data obtained are:
/ Dev/input/event1: 0003 0000 00000f18
/ Dev/input/event1: 0003 0001 00000e89
/ Dev/input/event1: 0001 014a 00000001
/ Dev/input/event1: 0000 0000 00000000
/ Dev/input/event1: 0003 0000 00003c5c
/ Dev/input/event1: 0003 0001 00000460
/ Dev/input/event1: 0001 014a 00000000
/ Dev/input/event1: 0000 0000 00000000
This data is not in the top left corner coordinates (0, 0) near the lower right corner has reached the coordinates (3864, 3721) and this number far beyond the (800, 480), ah.
I also tried the simulator under is 800 * 480 screen, the result is at (0, 0) between the (800, 480), which is how ah?
Reply:
This is the physical code. . . . . And hardware close. . . .
Reply:
Physics code
do not understand. Is there any way that can be (0, 0) to (800, 480) to a physical code that what you?
Reply:
If you know the range of XY physics codes, the ratio can be mapped
Personally feel that this issue should be made by the system, APP to do this live, a bit difficult, because the restrictions on individual programs are safer
Top, waiting for the master appears
Reply:
Reply:
I found a way.
ioctl ("/ dev/input/event1", EVIOCGABS (ABS_X), & info);
ioctl ("/ dev/input/event1", EVIOCGABS (ABS_Y), & info);
This range can be obtained.
EVIOCGABS, ABS_X, ABS_Y and input_absinfo structures are defined in
Reply:
Cow!
Also sendevent coordinate data on the simulator normal, but the device is not the problem, look: http :/ / blog.csdn.net/yiyaaixuexi/article/details/6574001
Reply:
There is a small problem
Like you said: "qtouch-touchscreen" is not dead event several provisions, saying 1234567 are likely to see your equipment up.
I want to determine which is the touch, which is the normal operating keys can and I do not know how to determine it. Perhaps take a look getevent code can be harvested.
Reply:
The problem has been resolved.
Reply:
Can your code to the next, I have encountered this problem, it is an emergency! ! ! Thank you very much! ! !
Reply:
I have this using the JNI. While to ROOT privileges.
# Include
# Include
# Include
# Include
# Include
# Include
# Include
/ / # Include "nativemethod.h"
# Define LOGI (...) __ android_log_print (ANDROID_LOG_INFO, "EventEmulate", __ VA_ARGS__)
# Define LOGE (...) __ android_log_print (ANDROID_LOG_ERROR, "EventEmulate", __ VA_ARGS__)
# Define DEV_DIR "/ dev / input"
# Define sizeof_bit_array (bits) ((bits + 7) / 8)
# Define test_bit (bit, array) (array [bit / 8] & (1 << (bit% 8)))
# Define ABS_MT_POSITION_X 0x35
# Define ABS_MT_POSITION_Y 0x36
struct EVENT_INFO
{
int fd_touch;
int fd_key;
int screen_width;
int screen_height;
int abs_x_min;
int abs_x_max;
int abs_y_min;
int abs_y_max;
};
int scan_dir (const char * dirname);
int open_dev (const char * deviceName);
int write_event (int fd, int type, int code, int value);
void calculateXY (float x, float y, int * abs_x, int * abs_y);
int containsNonZeroByte (const uint8_t * array, uint32_t startIndex, uint32_t endIndex);
struct EVENT_INFO ei;
int initEVT = 0;
int EVT_open (struct NATIVE_INFO * info)
{
struct input_absinfo absinfo;
if (initEVT)
return 0;
if (info == NULL)
{
LOGE ("info null point.");
goto fail;
}
if (info-> FB_width == 0 | | info-> FB_height == 0)
{
LOGE ("error width% d and height% d.", Info-> FB_width, info-> FB_height);
goto fail;
}
memset (& ei, 0, sizeof (ei));
ei.screen_width = info-> FB_width;
ei.screen_height = info-> FB_height;
scan_dir (DEV_DIR);
if (ioctl (ei.fd_touch, EVIOCGABS (ABS_X), & absinfo)) {
LOGI ("Error reading absolute controller ABS_X [% d]:% s", errno, strerror (errno));
return;
}
ei.abs_x_min = absinfo.minimum;
ei.abs_x_max = absinfo.maximum;
if (ioctl (ei.fd_touch, EVIOCGABS (ABS_Y), & absinfo)) {
LOGI ("Error reading absolute controller ABS_Y [% d]:% s", errno, strerror (errno));
return;
}
ei.abs_y_min = absinfo.minimum;
ei.abs_y_max = absinfo.maximum;
initEVT = 1;
return 0;
fail:
EVT_close ();
return -1;
}
int EVT_close ()
{
if (ei.fd_key> 0)
close (ei.fd_key);
if (ei.fd_touch> 0)
close (ei.fd_touch);
initEVT = 0;
return 0;
}
int EVT_touch (int action, float x, float y)
{
int abs_x, abs_y;
if (initEVT == 0)
{
LOGE ("event not inital");
return -1;
}
switch (action)
{
case ACTION_DOWN:
calculateXY (x, y, & abs_x, & abs_y);
write_event (ei.fd_touch, 3, 0, abs_x);
write_event (ei.fd_touch, 3, 1, abs_y);
write_event (ei.fd_touch, 1, 330, 1);
write_event (ei.fd_touch, 0, 0, 0);
break;
case ACTION_UP:
write_event (ei.fd_touch, 1, 330, 0);
write_event (ei.fd_touch, 0, 0, 0);
break;
case ACTION_MOVE:
calculateXY (x, y, & abs_x, & abs_y);
write_event (ei.fd_touch, 3, 0, abs_x);
write_event (ei.fd_touch, 3, 1, abs_y);
write_event (ei.fd_touch, 0, 0, 0);
break;
}
return 0;
}
int EVT_key (int action, int key)
{
if (initEVT == 0)
{
LOGE ("event not inital");
return -1;
}
switch (action)
{
case ACTION_DOWN:
write_event (ei.fd_key, 1, key, 1);
break;
case ACTION_UP:
write_event (ei.fd_key, 1, key, 0);
break;
}
return 0;
}
int scan_dir (const char * dirname)
{
char devname [PATH_MAX];
char * filename;
DIR * dir;
struct dirent * de;
dir = opendir (dirname);
if (dir == NULL)
return -1;
strcpy (devname, dirname);
filename = devname + strlen (devname);
* Filename + + = '/';
while ((de = readdir (dir))) {
if (de-> d_name [0] == '.' &&
(De-> d_name [1] == '\ 0' | |
(De-> d_name [1] == '.' && De-> d_name [2] == '\ 0')))
continue;
strcpy (filename, de-> d_name);
open_dev (devname);
}
closedir (dir);
return 0;
}
int open_dev (const char * deviceName)
{
int fd;
int version;
uint8_t key_bitmask [sizeof_bit_array (KEY_MAX + 1)];
uint8_t abs_bitmask [sizeof_bit_array (ABS_MAX + 1)];
fd = open (deviceName, O_RDWR);
if (fd <0) {
LOGI ("could not open device [% d]:% s", errno, strerror (errno));
return -1;
}
if (ioctl (fd, EVIOCGVERSION, & version)) {
return -1;
}
memset (key_bitmask, 0, sizeof (key_bitmask));
if (ioctl (fd, EVIOCGBIT (EV_KEY, sizeof (key_bitmask)), key_bitmask)> = 0) {
if (containsNonZeroByte (key_bitmask, 0, sizeof_bit_array (BTN_MISC))
| | ContainsNonZeroByte (key_bitmask, sizeof_bit_array (BTN_GAMEPAD),
sizeof_bit_array (BTN_DIGI))
| | ContainsNonZeroByte (key_bitmask, sizeof_bit_array (KEY_OK),
sizeof_bit_array (KEY_MAX + 1))) {
ei.fd_key = fd;
LOGI ("get key input device:% s", deviceName);
}
}
memset (abs_bitmask, 0, sizeof (abs_bitmask));
if (ioctl (fd, EVIOCGBIT (EV_ABS, sizeof (abs_bitmask)), abs_bitmask)> = 0) {
/ / Is this a new modern multi-touch driver?
if (test_bit (ABS_MT_POSITION_X, abs_bitmask)
&& Test_bit (ABS_MT_POSITION_Y, abs_bitmask)) {
ei.fd_touch = fd;
LOGI ("get multi-touch input device:% s", deviceName);
/ / Is this an old style single-touch driver?
} Else if (test_bit (BTN_TOUCH, key_bitmask)
&& Test_bit (ABS_X, abs_bitmask) && test_bit (ABS_Y, abs_bitmask)) {
ei.fd_touch = fd;
LOGI ("get single-touch input device:% s", deviceName);
}
}
}
int write_event (int fd, int type, int code, int value)
{
struct input_event event;
memset (& event, 0, sizeof (event));
event.type = type;
event.code = code;
event.value = value;
if (write (fd, & event, sizeof (event))LOGI ("write event failed [% d]:% s", errno, strerror (errno));
return -1;
}
return 0;
}
void calculateXY (float x, float y, int * abs_x, int * abs_y)
{
* Abs_x = ei.abs_x_min +
(Int) ((x * (float) (ei.abs_x_max - ei.abs_x_min)) / ei.screen_width + 0.5);
* Abs_y = ei.abs_y_min +
(Int) ((y * (float) (ei.abs_y_max - ei.abs_y_min)) / ei.screen_height + 0.5);
}
int containsNonZeroByte (const uint8_t * array, uint32_t startIndex, uint32_t endIndex)
{
const uint8_t * end = array + endIndex;
array + = startIndex;
while (array! = end) {
if (* (array + +)! = 0) {
return 1;
}
}
return 0;
}
Struct NATIVE_INFO structure which is my own definition. Which contains the screen width and height.
Reply:
Liu ~
Reply:
The landlord did not give header files. . . Compile various errors
Reply:
This is just to give you as a reference.
Only nativemethod.h header file that I wrote it myself, the other should all be there.
Reply:
The landlord can not give a definition of NATIVE_INFO?
Reply:
Recently, I also studied the landlord .... this is a white ... Can you say a little more points grateful amount ... ah ~ ~ ~ ~
Reply:
Brothers, I also need to solve the same problem, the landlord can give you copies of the source code
Reply:
Why can simulate this key value 122
Reply:
I refer to try it, found a different command format ACTION_DOWN ACTION_UP ACTION_MOVE on different devices need to send
Would like to ask how this place plus judge can write a generic. . .
I hope you have time gets advice
Here is what I wrote for two different devices function, do not know if you can add some written as a judge. . . .
Samsung follows
case AMOTION_EVENT_ACTION_DOWN:
calculateXY (x, y, & abs_x, & abs_y);
write_event (ei.fd_touch, 3, 57, 0);
write_event (ei.fd_touch, 3, 53, abs_x);
write_event (ei.fd_touch, 3, 54, abs_y);
write_event (ei.fd_touch, 3, 48, 20);
write_event (ei.fd_touch, 0, 0, 0);
break;
case AMOTION_EVENT_ACTION_UP:
write_event (ei.fd_touch, 3, 57, -1);
write_event (ei.fd_touch, 0, 0, 0);
break;
case AMOTION_EVENT_ACTION_MOVE:
calculateXY (x, y, & abs_x, & abs_y);
write_event (ei.fd_touch, 3, 53, abs_x);
write_event (ei.fd_touch, 3, 54, abs_y);
write_event (ei.fd_touch, 3, 48, 20);
write_event (ei.fd_touch, 0, 0, 0);
break;
Another device
case AMOTION_EVENT_ACTION_DOWN:
calculateXY (x, y, & abs_x, & abs_y);
write_event (ei.fd_touch, 3, 53, abs_x);
write_event (ei.fd_touch, 3, 54, abs_y);
write_event (ei.fd_touch, 3, 48, 1);
write_event (ei.fd_touch, 0, 2, 0);
write_event (ei.fd_touch, 0, 0, 0);
break;
case AMOTION_EVENT_ACTION_UP:
write_event (ei.fd_touch, 0, 2, 0);
write_event (ei.fd_touch, 0, 0, 0);
break;
case AMOTION_EVENT_ACTION_MOVE:
calculateXY (x, y, & abs_x, & abs_y);
write_event (ei.fd_touch, 3, 53, abs_x);
write_event (ei.fd_touch, 3, 54, abs_y);
write_event (ei.fd_touch, 3, 48, 1);
write_event (ei.fd_touch, 0, 2, 0);
write_event (ei.fd_touch, 0, 0, 0);
break;
No comments:
Post a Comment