/** * Finds an open device that has a name containing keypad. This probably is the event node * associated with the keypad Its purpose is to handle all hardware Android buttons such as Back, * Home, Volume, etc Key codes are defined in input.h (see NDK) , or use the Event Monitor to see * keypad messages This function sends the BACK key */ public void SendBackKeyToKeypad() { for (InputDevice idev : events.m_Devs) { // * Finds an open device that has a name containing keypad. This probably is the keypad // associated event node if (idev.getOpen() && idev.getName().contains("keypad")) { idev.SendKey(158, true); // Back key down idev.SendKey(158, false); // back key up } } }
/** * Finds an open device that has a name containing keypad. This probably is the event node * associated with the keypad Its purpose is to handle all hardware Android buttons such as Back, * Home, Volume, etc Key codes are defined in input.h (see NDK) , or use the Event Monitor to see * keypad messages This function sends the HOME key */ public void SendHomeKeyToKeypad() { boolean found = false; for (InputDevice idev : events.m_Devs) { // * Finds an open device that has a name containing keypad. This probably is the keypad // associated event node if (idev.getOpen() && idev.getName().contains("keypad")) { idev.SendKey(102, true); // home key down idev.SendKey(102, false); // home key up found = true; break; } } if (found == false) Toast.makeText(this, "Keypad not found.", Toast.LENGTH_SHORT).show(); }
/** * Handle events when the user selects a new item in the spinner. The spinner is used to select a * target for the Key and Touch buttons So what we do here, is to find which open-dev has been * selected from within our global events.m_Devs structure result saved in m_selectedDev, as the * index of our selected open dev. */ public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { int sel = arg2; int i = 0, j = 0; m_selectedDev = -1; for (InputDevice idev : events.m_Devs) { if (idev.getOpen()) { if (i == sel) { m_selectedDev = j; break; } else i++; } j++; } if (m_selectedDev != -1) { String name = events.m_Devs.get(m_selectedDev).getName(); Log.d(LT, "spinner selected:" + sel + " Name:" + name); Toast.makeText(this, "New device selected:" + name, Toast.LENGTH_SHORT).show(); } else Toast.makeText(this, "Invalid device selection!", Toast.LENGTH_SHORT).show(); }