IPhone simulated touch screen implementation event tutorial

Source: Internet
Author: User

IPhone touch screen SimulationImplementationEventThe tutorial is the content introduced in this article. Let's take a look at the content first. Now I have another ideaIPhoneThe idea of assisting in debugging is, of course, nothing about control, that is, to make some assistance on the screen, the assisted party should also perform the same operation, due to the uncertainty of the program to be debugged, it can only be used to send various screen-targetedSimulated Event.

Because apple did not release direct sendingTouch screen eventsSo I am using a jailbroken iPhone with PrivateFramework, and I am not expecting to go public. It is for internal debugging.

First, unplug the header file of the private framework from the kennytm website. For this application, you only need the GrapicsServices folder and Availability2.h. Import GraphicsService. framework under Platforms under the Xcode directory. The preparation is OK.

To send event messages, we mainly construct GSEventRecord. For simple events, we only need to fill in the type parameters in GSEventRecord. If it is more complex, we need to fill in the structure behind it, the fill size must be specified in the infoSize parameter.

C code

 
 
  1. typedef struct GSEventRecord {     
  2.     GSEventType type; // 0x8     
  3.     GSEventSubType subtype; // 0xC     
  4.     CGPoint location;   // 0x10     
  5.     CGPoint windowLocation; // 0x18     
  6.     int windowContextId;    // 0x20     
  7.     uint64_t timestamp; // 0x24, from mach_absolute_time     
  8.     GSWindowRef window; // 0x2C     
  9.     GSEventFlags flags; // 0x30     
  10.     unsigned senderPID; // 0x34     
  11.     CFIndex infoSize; // 0x38     
  12. } GSEventRecord;    
  13.  
  14. typedef struct GSEventRecord {  
  15.  GSEventType type; // 0x8  
  16.  GSEventSubType subtype; // 0xC  
  17.  CGPoint location;  // 0x10  
  18.  CGPoint windowLocation; // 0x18  
  19.  int windowContextId; // 0x20  
  20.  uint64_t timestamp; // 0x24, from mach_absolute_time  
  21.  GSWindowRef window; // 0x2C  
  22.  GSEventFlags flags; // 0x30  
  23.  unsigned senderPID; // 0x34  
  24.  CFIndex infoSize; // 0x38  
  25. } GSEventRecord; 

The header file does not provide some convenient methods to construct complex information structures, which is really different from the public API. However, some very simple messages can still be called directly, such as void GSEventLockDevice (); It is equivalent to constructing a GSEventRecord structure with the type of kGSEventLockDevice and then sending it out.

In a slightly complex example, we send a "Press" command to the {50, 50} coordinates of the screen.

C code

 
 
  1. #import "GSEvent.h"     
  2. #include <mach/mach_time.h>     
  3. void sendclickevent(){     
  4.     mach_port_t thePortOfApp = GSCopyPurpleNamedPort("com.fuckyou.fuck");     
  5.          
  6.     GSEventRecord header;     
  7.     GSHandInfo click;     
  8.     GSPathInfo pathInfo = {2,2,2,1,1,{50,50}, NULL};     
  9.          
  10.     bzero(&header, sizeof(header));     
  11.     bzero(&click, sizeof(click));     
  12.     
  13.     header.type = kGSEventHand;     
  14.     header.subtype = kGSEventSubTypeUnknown;     
  15.     header.location.x = 50;     
  16.     header.location.y = 50;     
  17.     header.windowLocation.x = 50;     
  18.     header.windowLocation.y = 50;     
  19.     header.infoSize = sizeof(GSHandInfo)+sizeof(GSPathInfo);     
  20.     header.timestamp = mach_absolute_time();     
  21.     
  22.     click.type = kGSHandInfoTypeTouchDown;     
  23.     click.deltaX = 1;     
  24.     click.deltaY = 1;     
  25.     click.pathInfosCount = 1;     
  26.          
  27.     struct    
  28.     {     
  29.         GSEventRecord record;     
  30.         GSHandInfo hand;     
  31.         GSPathInfo path;     
  32.     } record = {header, click, pathInfo};     
  33.          
  34.     GSSendEvent(&record, thePortOfApp);     
  35. }    
  36.  
  37. #import "GSEvent.h"  
  38. #include <mach/mach_time.h> 
  39. void sendclickevent(){  
  40.     mach_port_t thePortOfApp = GSCopyPurpleNamedPort("com.fuckyou.fuck");  
  41.       
  42.     GSEventRecord header;  
  43.     GSHandInfo click;  
  44.     GSPathInfo pathInfo = {2,2,2,1,1,{50,50}, NULL};  
  45.       
  46.     bzero(&header, sizeof(header));  
  47.     bzero(&click, sizeof(click));  
  48.  
  49.     header.type = kGSEventHand;  
  50.     header.subtype = kGSEventSubTypeUnknown;  
  51.     header.location.x = 50;  
  52.     header.location.y = 50;  
  53.     header.windowLocation.x = 50;  
  54.     header.windowLocation.y = 50;  
  55.     header.infoSize = sizeof(GSHandInfo)+sizeof(GSPathInfo);  
  56.     header.timestamp = mach_absolute_time();  
  57.  
  58.     click.type = kGSHandInfoTypeTouchDown;  
  59.     click.deltaX = 1;  
  60.     click.deltaY = 1;  
  61.     click.pathInfosCount = 1;  
  62.       
  63.     struct  
  64.     {  
  65.         GSEventRecord record;  
  66.         GSHandInfo hand;  
  67.         GSPathInfo path;  
  68.     } record = {header, click, pathInfo};  
  69.       
  70.     GSSendEvent(&record, thePortOfApp);  

It should be noted that an application must receive the port, that is, the first line of code, to send events to an application. However, to send complex information, you must splice several pieces of information together. It is more appropriate to define a structure for writing and enter the size of the information body correctly, these skills seem to have returned to the wild age. I saw a 0-long array and constructed the structure on the heap. However, the processing of these messages is asynchronous, and I don't know when the memory can be safely recycled, therefore, we recommend that you use the structure concatenation method.

In addition to the touch screen, another important thing is the keyboard input, but the iPhone input is not very special, it is said that the keyboard input, it means that.

The specific encoding process is actually no different from that of a touch screen event. However, if the structure name of a keyboard event, such as GSHardwareKeyInfo or GSKeyInfo, appears to be searched by google, no result is returned, at the beginning, I still wanted to get together. It took two or three days to get together and I couldn't find out that it could actually be reversed. I used GSEventCreateKeyEvent to create a keyboard event, and then I parsed it, so I got it done in this way, and sadly, I think too much about it, and the vast majority of the members can fill in 0. There is no need to worry about coding areas.

Objective-c code

 
 
  1. GSEventRecord header;     
  2. GSHardwareKeyInfo key = {0,0,0,0,1,{'a'},1,{'a'},0,0,0,0};     
  3. memset(&header, 0, sizeof(header));     
  4.     
  5. header.type = kGSEventKeyDown;     
  6. header.infoSize = sizeof(GSHardwareKeyInfo);     
  7. header.timestamp = mach_absolute_time();     
  8.     
  9. struct     
  10. {     
  11.     GSEventRecord header1;     
  12.     GSHardwareKeyInfo key1;     
  13. }fuck = {header, key};     
  14. GSSendEvent(&fuck, GSGetPurpleApplicationPort());    
  15.  
  16.     GSEventRecord header;  
  17.     GSHardwareKeyInfo key = {0,0,0,0,1,{'a'},1,{'a'},0,0,0,0};  
  18.     memset(&header, 0, sizeof(header));  
  19.       
  20.     header.type = kGSEventKeyDown;  
  21.     header.infoSize = sizeof(GSHardwareKeyInfo);  
  22.     header.timestamp = mach_absolute_time();  
  23.       
  24.     struct  
  25.     {  
  26.         GSEventRecord header1;  
  27.         GSHardwareKeyInfo key1;  
  28.     }fuck = {header, key};  
  29.     GSSendEvent(&fuck, GSGetPurpleApplicationPort()); 

In this way, you can enter a, provided that the cursor must be in the input box.

Of course there are still many problems in the future. This is actually just an event that your program sends to itself. What needs to be done later is to send events to the front-end program or even the main interface when the program is running on the background. Can you do this, i'm not sure.

Summary:IPhone touch screen SimulationImplementationEventI hope this article will help you with the introduction of this tutorial! For more information, see edit recommendations.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.