1. initialize key ing (File framework/base/libs/UI/eventhub. cpp)
Eventhub: opendevice ()
-----> // Snprintf (keylayoutfilename, sizeof (keylayoutfilename ),
// "% S/usr/keylayout/% S. KL", root, tmpfn); confirm the key ing file name. The key ing file is in (definition of Qwerty. KL full keyboard)
// A. android_root/usr/keylayout/*. KL in the root file system
// B. Under the respective project directories in the source code, such as device/product/*. KL
Keylayoutmap: load () parses the key ing configuration file to complete key ing initialization and other operations,
Generate a key ing, m_keys, vector Member, in keylayoutmap.
The main process is:
A. parse each line of *. KL to get the ing string between the underlying keycode and the key mapped to the Android system.
B. obtain the corresponding Android keycode from keycodes [] using the android string (keycodelabels. h)
C. Bind the original keycode and the obtained Android keycode to the m_keys vector member.
2. Obtain the event (File framework/base/libs/UI/eventhub. cpp)
Eventhub: getevent ()
---> // Read input data from the input file
Keylayoutmap: Map () parses the input data read, and obtains the key code required by Android from m_keys, a vector member in the initialized keylayoutmap.
The parsing code is as follows:
Ssize_t Index = m_keys.indexofkey (scancode); // obtain the key code from the input data and obtain the index corresponding to the vector.
Const key & K = m_keys.valueat (INDEX); // you can use the index to find the android keycode mapped to it.