/* * IN_Android_KeyEvent2UCS */ static wchar_t IN_Android_KeyEvent2UCS( const AInputEvent *event ) { JNIEnv *env = Sys_Android_GetJNIEnv(); static jclass mapClass; static jmethodID load, get; jobject map; unsigned int ucs; if( !mapClass ) { jclass mapClassRef; mapClassRef = (*env)->FindClass( env, "android/view/KeyCharacterMap" ); mapClass = (*env)->NewGlobalRef( env, mapClassRef ); load = (*env)->GetStaticMethodID( env, mapClass, "load", "(I)Landroid/view/KeyCharacterMap;" ); get = (*env)->GetMethodID( env, mapClass, "get", "(II)I" ); (*env)->DeleteLocalRef( env, mapClassRef ); } map = (*env)->CallStaticObjectMethod( env, mapClass, load, AInputEvent_getDeviceId( event ) ); ucs = (*env)->CallIntMethod( env, map, get, AKeyEvent_getKeyCode( event ), AKeyEvent_getMetaState( event ) ); (*env)->DeleteLocalRef( env, map ); return ucs; }
int32_t Engine::onMotionEvent(android_app* app, AInputEvent* event) { if (!this->loaded) return 0; if (!this->focused) return 0; size_t pointerCount = AMotionEvent_getPointerCount(event); this->updateUptime(); for (size_t i = 0; i < pointerCount; i++) { size_t pointerId = AMotionEvent_getPointerId(event, i); size_t action = AMotionEvent_getAction(event) & AMOTION_EVENT_ACTION_MASK; size_t pointerIndex = i; if (action == AMOTION_EVENT_ACTION_POINTER_DOWN || action == AMOTION_EVENT_ACTION_POINTER_UP) { pointerIndex = (AMotionEvent_getAction(event) & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT; pointerId = AMotionEvent_getPointerId(event, pointerIndex); } this->touchEventParamCache[0] = pointerId; this->touchEventParamCache[1] = action; this->touchEventParamCache[2] = AMotionEvent_getX(event, pointerIndex); this->touchEventParamCache[3] = AMotionEvent_getY(event, pointerIndex); this->touchEventParamCache[4] = this->uptime.time; this->touchEventParamCache[5] = this->uptime.millitm; this->touchEventParamCache[6] = AInputEvent_getDeviceId(event); this->touchEventParamCache[7] = AInputEvent_getSource(event); if (callSqFunction_Bool_Floats(this->sqvm, EMO_NAMESPACE, EMO_FUNC_MOTIONEVENT, this->touchEventParamCache, MOTION_EVENT_PARAMS_SIZE, false)) { return 1; } }
bool CAndroidJoyStick::onJoyStickMotionEvent(AInputEvent *event) { if (event == NULL) return false; // match this device to a created device struct, // create it if we do not find it. APP_InputDeviceAxes *device_axes = NULL; int32_t device = AInputEvent_getDeviceId(event); // look for device name in our inputdevice cache. for (size_t i = 0; i < m_input_devices.size(); i++) { if (m_input_devices[i]->id == device) device_axes = m_input_devices[i]; } if (!device_axes) { // as we see each axis, create a device axes and cache it. device_axes = new APP_InputDeviceAxes; SetupJoySticks(device_axes, device); m_input_devices.push_back(device_axes); } // handle queued motion events, we // ingnore history as it only relates to touch. for (size_t p = 0; p < AMotionEvent_getPointerCount(event); p++) ProcessMotionEvents(event, p, device, device_axes); return true; }
static bool CookEvent_Motion(AInputEvent *event, CookedEventCallback callback) { int src = AInputEvent_getSource(event); int action = AMotionEvent_getAction(event); int actionMasked = action & AMOTION_EVENT_ACTION_MASK; int ptrIndex = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT; struct CookedEvent ev; memset(&ev, 0, sizeof(ev)); if (actionMasked == AMOTION_EVENT_ACTION_DOWN || actionMasked == AMOTION_EVENT_ACTION_POINTER_DOWN) { ev.type = COOKED_EVENT_TYPE_POINTER_DOWN; } else if (actionMasked == AMOTION_EVENT_ACTION_UP || actionMasked == AMOTION_EVENT_ACTION_POINTER_UP) { ev.type = COOKED_EVENT_TYPE_POINTER_UP; } else { ev.type = COOKED_EVENT_TYPE_POINTER_MOVE; } ev.motionPointerId = AMotionEvent_getPointerId(event, ptrIndex); ev.motionIsOnScreen = (src == AINPUT_SOURCE_TOUCHSCREEN); ev.motionX = AMotionEvent_getX(event, ptrIndex); ev.motionY = AMotionEvent_getY(event, ptrIndex); if (ev.motionIsOnScreen) { // use screen size as the motion range ev.motionMinX = 0.0f; ev.motionMaxX = SceneManager::GetInstance()->GetScreenWidth(); ev.motionMinY = 0.0f; ev.motionMaxY = SceneManager::GetInstance()->GetScreenHeight(); } else { // look up motion range for this device _look_up_motion_range((int) AInputEvent_getDeviceId(event), (int)AInputEvent_getSource(event), &ev.motionMinX, &ev.motionMaxX, &ev.motionMinY, &ev.motionMaxY); } // deliver event callback(&ev); // deliver motion info about other pointers (for multi-touch) int ptrCount = AMotionEvent_getPointerCount(event); for (int i = 0; i < ptrCount; i++) { ev.type = COOKED_EVENT_TYPE_POINTER_MOVE; ev.motionX = AMotionEvent_getX(event, i); ev.motionY = AMotionEvent_getY(event, i); ev.motionPointerId = AMotionEvent_getPointerId(event, i); callback(&ev); } // If this is a touch-nav event, return false to indicate that we haven't handled it. // This will trigger translation of swipes to DPAD keys, which is what we want. // Otherwise, we say that we've handled it. return (src != SOURCE_TOUCH_NAVIGATION); }
int32_t getKeyRune(JNIEnv* env, AInputEvent* e) { return (int32_t)(*env)->CallIntMethod( env, current_ctx, key_rune_method, AInputEvent_getDeviceId(e), AKeyEvent_getKeyCode(e), AKeyEvent_getMetaState(e) ); }
void WindowImplAndroid::processScrollEvent(AInputEvent* _event, ActivityStates* states) { // Prepare the java virtual machine jint lResult; jint lFlags = 0; JavaVM* lJavaVM = states->activity->vm; JNIEnv* lJNIEnv = states->activity->env; JavaVMAttachArgs lJavaVMAttachArgs; lJavaVMAttachArgs.version = JNI_VERSION_1_6; lJavaVMAttachArgs.name = "NativeThread"; lJavaVMAttachArgs.group = NULL; lResult=lJavaVM->AttachCurrentThread(&lJNIEnv, &lJavaVMAttachArgs); if (lResult == JNI_ERR) err() << "Failed to initialize JNI, couldn't get the unicode value" << std::endl; // Retrieve everything we need to create this MotionEvent in java jlong downTime = AMotionEvent_getDownTime(_event); jlong eventTime = AMotionEvent_getEventTime(_event); jint action = AMotionEvent_getAction(_event); jfloat x = AMotionEvent_getX(_event, 0); jfloat y = AMotionEvent_getY(_event, 0); jfloat pressure = AMotionEvent_getPressure(_event, 0); jfloat size = AMotionEvent_getSize(_event, 0); jint metaState = AMotionEvent_getMetaState(_event); jfloat xPrecision = AMotionEvent_getXPrecision(_event); jfloat yPrecision = AMotionEvent_getYPrecision(_event); jint deviceId = AInputEvent_getDeviceId(_event); jint edgeFlags = AMotionEvent_getEdgeFlags(_event); // Create the MotionEvent object in java trough its static constructor obtain() jclass ClassMotionEvent = lJNIEnv->FindClass("android/view/MotionEvent"); jmethodID StaticMethodObtain = lJNIEnv->GetStaticMethodID(ClassMotionEvent, "obtain", "(JJIFFFFIFFII)Landroid/view/MotionEvent;"); jobject ObjectMotionEvent = lJNIEnv->CallStaticObjectMethod(ClassMotionEvent, StaticMethodObtain, downTime, eventTime, action, x, y, pressure, size, metaState, xPrecision, yPrecision, deviceId, edgeFlags); // Call its getAxisValue() method to get the delta value of our wheel move event jmethodID MethodGetAxisValue = lJNIEnv->GetMethodID(ClassMotionEvent, "getAxisValue", "(I)F"); jfloat delta = lJNIEnv->CallFloatMethod(ObjectMotionEvent, MethodGetAxisValue, 0x00000001); // Create and send our mouse wheel event Event event; event.type = Event::MouseWheelMoved; event.mouseWheel.delta = static_cast<double>(delta); event.mouseWheel.x = AMotionEvent_getX(_event, 0); event.mouseWheel.y = AMotionEvent_getY(_event, 0); forwardEvent(event); // Dettach this thread from the JVM lJavaVM->DetachCurrentThread(); }
bool CAndroidJoyStick::onJoyStickKeyEvent(AInputEvent *event) { if (event == NULL) return false; int32_t keycode = AKeyEvent_getKeyCode(event); // watch this check, others might be different. // AML IR Controller is AINPUT_SOURCE_GAMEPAD | AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_DPAD // Gamestick Controller == AINPUT_SOURCE_GAMEPAD | AINPUT_SOURCE_KEYBOARD // NVidiaShield Controller == AINPUT_SOURCE_GAMEPAD | AINPUT_SOURCE_KEYBOARD // we want to reject AML IR Controller. if (AInputEvent_getSource(event) == (AINPUT_SOURCE_GAMEPAD | AINPUT_SOURCE_KEYBOARD)) { // GamePad events are AINPUT_EVENT_TYPE_KEY events, // trap them here and revector valid ones as JoyButtons // so we get keymap handling. for (size_t i = 0; i < sizeof(ButtonMap) / sizeof(KeyMap); i++) { if (keycode == ButtonMap[i].nativeKey) { uint32_t holdtime = 0; uint8_t button = ButtonMap[i].xbmcID; int32_t action = AKeyEvent_getAction(event); int32_t device = AInputEvent_getDeviceId(event); if ((action == AKEY_EVENT_ACTION_UP)) { // ProcessJoystickEvent does not understand up, ignore it. m_prev_holdtime = m_prev_device = m_prev_button = 0; return false; } else { if (m_prev_holdtime && device == m_prev_device && button == m_prev_button) { holdtime = CTimeUtils::GetFrameTime() - m_prev_holdtime; } else { m_prev_holdtime = CTimeUtils::GetFrameTime(); m_prev_device = device; m_prev_button = button; } } XBMC_JoyButton(device, button, holdtime, action == AKEY_EVENT_ACTION_UP); return true; } } } return false; }
int WindowImplAndroid::getUnicode(AInputEvent* event) { // Retrieve activity states ActivityStates* states = getActivity(NULL); Lock lock(states->mutex); // Initializes JNI jint lResult; jint lFlags = 0; JavaVM* lJavaVM = states->activity->vm; JNIEnv* lJNIEnv = states->activity->env; JavaVMAttachArgs lJavaVMAttachArgs; lJavaVMAttachArgs.version = JNI_VERSION_1_6; lJavaVMAttachArgs.name = "NativeThread"; lJavaVMAttachArgs.group = NULL; lResult=lJavaVM->AttachCurrentThread(&lJNIEnv, &lJavaVMAttachArgs); if (lResult == JNI_ERR) err() << "Failed to initialize JNI, couldn't get the Unicode value" << std::endl; // Retrieve key data from the input event jlong downTime = AKeyEvent_getDownTime(event); jlong eventTime = AKeyEvent_getEventTime(event); jint action = AKeyEvent_getAction(event); jint code = AKeyEvent_getKeyCode(event); jint repeat = AKeyEvent_getRepeatCount(event); // not sure! jint metaState = AKeyEvent_getMetaState(event); jint deviceId = AInputEvent_getDeviceId(event); jint scancode = AKeyEvent_getScanCode(event); jint flags = AKeyEvent_getFlags(event); jint source = AInputEvent_getSource(event); // Construct a KeyEvent object from the event data jclass ClassKeyEvent = lJNIEnv->FindClass("android/view/KeyEvent"); jmethodID KeyEventConstructor = lJNIEnv->GetMethodID(ClassKeyEvent, "<init>", "(JJIIIIIIII)V"); jobject ObjectKeyEvent = lJNIEnv->NewObject(ClassKeyEvent, KeyEventConstructor, downTime, eventTime, action, code, repeat, metaState, deviceId, scancode, flags, source); // Call its getUnicodeChar() method to get the Unicode value jmethodID MethodGetUnicode = lJNIEnv->GetMethodID(ClassKeyEvent, "getUnicodeChar", "(I)I"); int unicode = lJNIEnv->CallIntMethod(ObjectKeyEvent, MethodGetUnicode, metaState); lJNIEnv->DeleteLocalRef(ClassKeyEvent); lJNIEnv->DeleteLocalRef(ObjectKeyEvent); // Detach this thread from the JVM lJavaVM->DetachCurrentThread(); return unicode; }
extern "C" int AndroidGetKeyText( AInputEvent *event ) { int result = 0; // Attaches the current thread to the JVM. jint lResult; jint lFlags = 0; JavaVM* lJavaVM = engine.app->activity->vm; JNIEnv* lJNIEnv = engine.app->activity->env; JavaVMAttachArgs lJavaVMAttachArgs; lJavaVMAttachArgs.version = JNI_VERSION_1_6; lJavaVMAttachArgs.name = "NativeThread"; lJavaVMAttachArgs.group = NULL; lResult=lJavaVM->AttachCurrentThread(&lJNIEnv, &lJavaVMAttachArgs); if (lResult == JNI_ERR) { return 0; } // Retrieves NativeActivity. jobject lNativeActivity = engine.app->activity->clazz; jclass ClassNativeActivity = lJNIEnv->GetObjectClass(lNativeActivity); jmethodID MethodSetFlags = lJNIEnv->GetMethodID( ClassNativeActivity, "getKeyText", "(JJIIIIIII)I"); lprintf( "..." ); if( MethodSetFlags ) result = lJNIEnv->CallIntMethod( lNativeActivity, MethodSetFlags , AKeyEvent_getDownTime(event) , AKeyEvent_getEventTime(event) , AKeyEvent_getAction(event) , AKeyEvent_getKeyCode(event) , AKeyEvent_getRepeatCount(event) , AKeyEvent_getMetaState(event) , AInputEvent_getDeviceId(event) , AKeyEvent_getScanCode(event) , AKeyEvent_getFlags(event) ); else { lprintf( "Failed to get method." ); result = 0; } // Finished with the JVM. lJavaVM->DetachCurrentThread(); return result; }
bool OuyaInputView::dispatchKeyEvent(AInputEvent* keyEvent) { int64_t downTime = AKeyEvent_getDownTime(keyEvent); int64_t eventTime = AKeyEvent_getEventTime(keyEvent); int32_t action = AKeyEvent_getAction(keyEvent); int32_t code = AKeyEvent_getKeyCode(keyEvent); int32_t repeat = AKeyEvent_getRepeatCount(keyEvent); int32_t metaState = AKeyEvent_getMetaState(keyEvent); int32_t deviceId = AInputEvent_getDeviceId(keyEvent); int32_t scancode = AKeyEvent_getScanCode(keyEvent); int32_t flags = AKeyEvent_getFlags(keyEvent); int32_t source = AInputEvent_getSource(keyEvent); #if ENABLE_VERBOSE_LOGGING __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, "downTime=%lld eventTime=%lld action=%d code=%d repeat=%d metaState=%d deviceId=%d scancode=%d flags=%d source=%d", downTime, eventTime, action, code, repeat, metaState, deviceId, scancode, flags, source); #endif return javaDispatchKeyEvent(downTime, eventTime, action, code, repeat, metaState, deviceId, scancode, flags, source); }
static void _log_event(AInputEvent *event) { if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_KEY) { LOGD("DEBUG: Key event: action=%d, keycode=%d, meta=0x%x, source=%d", AKeyEvent_getAction(event), AKeyEvent_getKeyCode(event), AKeyEvent_getMetaState(event), (int)(AInputEvent_getSource(event))); } else if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION) { LOGD("DEBUG: Motion event: deviceid=%d, pointerid=%d, sourceid=%d, action=%d, keycode=%d" "x,y=%f,%f, raw x,y=%f,%f, source=%d", (int)AInputEvent_getDeviceId(event), (int)AMotionEvent_getPointerId(event, 0), (int)AInputEvent_getSource(event), (int)AKeyEvent_getAction(event), (int)AKeyEvent_getKeyCode(event), (float)AMotionEvent_getX(event,0), (float)AMotionEvent_getY(event,0), (float)AMotionEvent_getRawX(event,0), (float)AMotionEvent_getRawY(event,0), (int)(AInputEvent_getSource(event))); } else { LOGD("DEBUG: other type of event, %d", AInputEvent_getType(event)); } }
bool OuyaInputView::dispatchGenericMotionEvent(AInputEvent* motionEvent) { int64_t downTime = AMotionEvent_getDownTime(motionEvent); int64_t eventTime = AMotionEvent_getEventTime(motionEvent); int32_t action = AMotionEvent_getAction(motionEvent); int32_t metaState = AMotionEvent_getMetaState(motionEvent); int32_t pointerCount = AMotionEvent_getPointerCount(motionEvent); int32_t buttonState = AMotionEvent_getButtonState(motionEvent); float xPrecision = AMotionEvent_getXPrecision(motionEvent); float yPrecision = AMotionEvent_getYPrecision(motionEvent); int32_t deviceId = AInputEvent_getDeviceId(motionEvent); int32_t edgeFlags = AMotionEvent_getEdgeFlags(motionEvent); int32_t flags = AMotionEvent_getFlags(motionEvent); int32_t source = AInputEvent_getSource(motionEvent); int* pointerPropertiesId = new int[pointerCount]; int* pointerPropertiesToolType = new int[pointerCount]; float* pointerCoordsOrientation = new float[pointerCount]; float* pointerCoordsPressure = new float[pointerCount]; float* pointerCoordsSize = new float[pointerCount]; float* pointerCoordsToolMajor = new float[pointerCount]; float* pointerCoordsToolMinor = new float[pointerCount]; float* pointerCoordsTouchMajor = new float[pointerCount]; float* pointerCoordsTouchMinor = new float[pointerCount]; float* pointerCoordsX = new float[pointerCount]; float* pointerCoordsY = new float[pointerCount]; std::vector<int> listAxisIndices; std::vector<float> listAxisValues; if (pointerCount > 0) { #if ENABLE_VERBOSE_LOGGING __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, "pointerCount=%d deviceId=%d source=%d", pointerCount, deviceId, source); #endif // MotionEvent.PointerProperties long long pointerId = AMotionEvent_getPointerId(motionEvent, 0); int32_t toolType = AMotionEvent_getToolType(motionEvent, 0); #if ENABLE_VERBOSE_LOGGING __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, "PointerProperties pointerId=%lld toolType-%d", pointerId, toolType); #endif pointerPropertiesId[0] = pointerId; pointerPropertiesToolType[0] = toolType; // MotionEvent.PointerCoords float orientation = AMotionEvent_getOrientation(motionEvent, pointerId); float pressure = AMotionEvent_getPressure(motionEvent, pointerId); float size = AMotionEvent_getSize(motionEvent, pointerId); float toolMajor = AMotionEvent_getTouchMajor(motionEvent, pointerId); float toolMinor = AMotionEvent_getToolMinor(motionEvent, pointerId); float touchMajor = AMotionEvent_getTouchMajor(motionEvent, pointerId); float touchMinor = AMotionEvent_getTouchMinor(motionEvent, pointerId); float x = AMotionEvent_getX(motionEvent, pointerId); float y = AMotionEvent_getY(motionEvent, pointerId); #if ENABLE_VERBOSE_LOGGING __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, "PointerCoords orientation=%f pressure=%f size=%f toolMajor=%f toolMinor=%f touchMajor=%f touchMinor=%f x=%f y=%f", orientation, pressure, size, toolMajor, toolMinor, touchMajor, touchMinor, x, y); #endif pointerCoordsOrientation[0] = orientation; pointerCoordsPressure[0] = pressure; pointerCoordsSize[0] = size; pointerCoordsToolMajor[0] = toolMajor; pointerCoordsToolMinor[0] = toolMinor; pointerCoordsTouchMajor[0] = touchMajor; pointerCoordsTouchMinor[0] = touchMinor; pointerCoordsX[0] = x; pointerCoordsY[0] = y; for (int32_t axis = 0; axis < 50; ++axis) // 50 is based on the AXIS_value range I saw in the documentation { float val = AMotionEvent_getAxisValue(motionEvent, axis, pointerId); if (val != 0.0f) { #if ENABLE_VERBOSE_LOGGING __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, "axis=%d val=%f", axis, val); #endif listAxisIndices.push_back(axis); listAxisValues.push_back(val); } } } int axisCount = listAxisIndices.size(); int* axisIndexes = new int[axisCount]; float* axisValues = new float[axisCount]; for (int index = 0; index < axisCount; ++index) { axisIndexes[index] = listAxisIndices[index]; axisValues[index] = listAxisValues[index]; } listAxisIndices.clear(); listAxisValues.clear(); bool handled = javaDispatchGenericMotionEvent( downTime, eventTime, action, pointerCount, metaState, buttonState, xPrecision, yPrecision, deviceId, edgeFlags, source, flags, pointerPropertiesId, pointerPropertiesToolType, pointerCoordsOrientation, pointerCoordsPressure, pointerCoordsSize, pointerCoordsToolMajor, pointerCoordsToolMinor, pointerCoordsTouchMajor, pointerCoordsTouchMinor, pointerCoordsX, pointerCoordsY, axisCount, axisIndexes, axisValues); delete pointerPropertiesId; delete pointerPropertiesToolType; delete pointerCoordsOrientation; delete pointerCoordsPressure; delete pointerCoordsSize; delete pointerCoordsToolMajor; delete pointerCoordsToolMinor; delete pointerCoordsTouchMajor; delete pointerCoordsTouchMinor; delete pointerCoordsX; delete pointerCoordsY; delete axisIndexes; delete axisValues; return handled; }
bool CAndroidKey::onKeyboardEvent(AInputEvent *event) { if (event == NULL) return false; int32_t flags = AKeyEvent_getFlags(event); int32_t state = AKeyEvent_getMetaState(event); int32_t action = AKeyEvent_getAction(event); int32_t repeat = AKeyEvent_getRepeatCount(event); int32_t keycode = AKeyEvent_getKeyCode(event); int32_t deviceId = AInputEvent_getDeviceId(event); CJNIKeyCharacterMap map = CJNIKeyCharacterMap::load(deviceId); uint16_t unicode = map.get(keycode, state); // Check if we got some special key uint16_t sym = XBMCK_UNKNOWN; for (unsigned int index = 0; index < sizeof(keyMap) / sizeof(KeyMap); index++) { if (keycode == keyMap[index].nativeKey) { sym = keyMap[index].xbmcKey; break; } } if (m_handleMediaKeys) { for (unsigned int index = 0; index < sizeof(MediakeyMap) / sizeof(KeyMap); index++) { if (keycode == MediakeyMap[index].nativeKey) { sym = MediakeyMap[index].xbmcKey; break; } } } // check if this is a key we don't want to handle if (sym == XBMCK_LAST || sym == XBMCK_UNKNOWN) { CXBMCApp::android_printf("CAndroidKey: key ignored (code: %d)", keycode); return false; } uint16_t modifiers = 0; if (state & AMETA_ALT_LEFT_ON) modifiers |= XBMCKMOD_LALT; if (state & AMETA_ALT_RIGHT_ON) modifiers |= XBMCKMOD_RALT; if (state & AMETA_SHIFT_LEFT_ON) modifiers |= XBMCKMOD_LSHIFT; if (state & AMETA_SHIFT_RIGHT_ON) modifiers |= XBMCKMOD_RSHIFT; if (state & AMETA_CTRL_LEFT_ON) modifiers |= XBMCKMOD_LCTRL; if (state & AMETA_CTRL_RIGHT_ON) modifiers |= XBMCKMOD_RCTRL; /* TODO: if (state & AMETA_SYM_ON) modifiers |= 0x000?;*/ switch (action) { case AKEY_EVENT_ACTION_DOWN: #if 1 CXBMCApp::android_printf("CAndroidKey: key down (code: %d; repeat: %d; flags: 0x%0X; alt: %s; shift: %s; sym: %s)", keycode, repeat, flags, (state & AMETA_ALT_ON) ? "yes" : "no", (state & AMETA_SHIFT_ON) ? "yes" : "no", (state & AMETA_SYM_ON) ? "yes" : "no"); #endif XBMC_Key((uint8_t)keycode, sym, modifiers, unicode, false); return true; case AKEY_EVENT_ACTION_UP: #if 1 CXBMCApp::android_printf("CAndroidKey: key up (code: %d; repeat: %d; flags: 0x%0X; alt: %s; shift: %s; sym: %s)", keycode, repeat, flags, (state & AMETA_ALT_ON) ? "yes" : "no", (state & AMETA_SHIFT_ON) ? "yes" : "no", (state & AMETA_SYM_ON) ? "yes" : "no"); #endif XBMC_Key((uint8_t)keycode, sym, modifiers, unicode, true); return true; case AKEY_EVENT_ACTION_MULTIPLE: #if 1 CXBMCApp::android_printf("CAndroidKey: key multiple (code: %d; repeat: %d; flags: 0x%0X; alt: %s; shift: %s; sym: %s)", keycode, repeat, flags, (state & AMETA_ALT_ON) ? "yes" : "no", (state & AMETA_SHIFT_ON) ? "yes" : "no", (state & AMETA_SYM_ON) ? "yes" : "no"); #endif break; default: #if 1 CXBMCApp::android_printf("CAndroidKey: unknown key (code: %d; repeat: %d; flags: 0x%0X; alt: %s; shift: %s; sym: %s)", keycode, repeat, flags, (state & AMETA_ALT_ON) ? "yes" : "no", (state & AMETA_SHIFT_ON) ? "yes" : "no", (state & AMETA_SYM_ON) ? "yes" : "no"); #endif break; } return false; }
void StWindowImpl::onAndroidInput(const AInputEvent* theEvent, bool& theIsProcessed) { const int anEventType = AInputEvent_getType(theEvent); switch(anEventType) { case AINPUT_EVENT_TYPE_KEY: { StVirtKey aVKeySt = ST_VK_NULL; int32_t aKeySym = AKeyEvent_getKeyCode(theEvent); if(aKeySym < ST_ANDROID2ST_VK_SIZE) { aVKeySt = (StVirtKey )ST_ANDROID2ST_VK[aKeySym]; } if(aVKeySt == ST_VK_NULL) { return; } myStEvent.Key.Time = getEventTime(); //AKeyEvent_getEventTime(theEvent); myStEvent.Key.VKey = aVKeySt; myStEvent.Key.Char = 0; const int32_t aKeyAction = AKeyEvent_getAction(theEvent); if(aKeyAction == AKEY_EVENT_ACTION_DOWN) { postKeyDown(myStEvent); } else if(aKeyAction == AKEY_EVENT_ACTION_UP) { postKeyUp(myStEvent); }// else if(aKeyAction == AKEY_EVENT_ACTION_MULTIPLE) {} return; } case AINPUT_EVENT_TYPE_MOTION: { theIsProcessed = true; const int32_t aSource = AInputEvent_getSource(theEvent); const int32_t anActionPak = AMotionEvent_getAction(theEvent); const int32_t anAction = anActionPak & AMOTION_EVENT_ACTION_MASK; const size_t anActionPntIndex = anActionPak & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK; //const StRectI_t& aWinRect = attribs.IsFullScreen ? myRectFull : myRectNorm; const StRectI_t& aWinRect = myRectNorm; const float aWinSizeX = aWinRect.width(); const float aWinSizeY = aWinRect.height(); // at least single point is defined StPointD_t aPos0(double(AMotionEvent_getX(theEvent, 0)) / double(aWinSizeX), double(AMotionEvent_getY(theEvent, 0)) / double(aWinSizeY)); myStEvent.Type = stEvent_None; myStEvent.Base.Time = getEventTime(); /// int64_t AMotionEvent_getEventTime(theEvent); switch(aSource) { case AINPUT_SOURCE_TOUCHSCREEN: case AINPUT_SOURCE_TOUCHPAD: { const size_t aNbTouches = AMotionEvent_getPointerCount(theEvent); myStEvent.Touch.NbTouches = std::min(aNbTouches, (size_t )ST_MAX_TOUCHES); bool isUp = anAction == AMOTION_EVENT_ACTION_UP || anAction == AMOTION_EVENT_ACTION_POINTER_UP; if(isUp) { myStEvent.Touch.NbTouches = std::max(myStEvent.Touch.NbTouches - 1, 0); } for(size_t aTouchIter = 0; aTouchIter < ST_MAX_TOUCHES; ++aTouchIter) { StTouch& aTouch = myStEvent.Touch.Touches[aTouchIter]; aTouch = StTouch::Empty(); if(aTouchIter == anActionPntIndex && isUp) { continue; } if(aTouchIter >= aNbTouches) { continue; } aTouch.Id = AMotionEvent_getPointerId(theEvent, aTouchIter); aTouch.DeviceId = AInputEvent_getDeviceId(theEvent); aTouch.OnScreen = aSource == AINPUT_SOURCE_TOUCHSCREEN; const float aPosX = AMotionEvent_getX(theEvent, aTouchIter); const float aPosY = AMotionEvent_getY(theEvent, aTouchIter); aTouch.PointX = (aPosX - float(aWinRect.left())) / aWinSizeX; aTouch.PointY = (aPosY - float(aWinRect.top())) / aWinSizeY; } switch(anAction) { case AMOTION_EVENT_ACTION_DOWN: case AMOTION_EVENT_ACTION_POINTER_DOWN: { myStEvent.Type = stEvent_TouchDown; doTouch(myStEvent.Touch); if(aNbTouches == 1) { // simulate mouse click myMousePt = aPos0; myIsPreciseCursor = false; myStEvent.Type = stEvent_MouseDown; myStEvent.Button.Button = ST_MOUSE_LEFT; myStEvent.Button.Buttons = 0; myStEvent.Button.PointX = myMousePt.x(); myStEvent.Button.PointY = myMousePt.y(); signals.onMouseDown->emit(myStEvent.Button); } else if(aNbTouches == 2) { // emit special event to cancel previously simulated click myStEvent.Type = stEvent_MouseCancel; myStEvent.Button.Button = ST_MOUSE_LEFT; myStEvent.Button.Buttons = 0; myStEvent.Button.PointX = myMousePt.x(); myStEvent.Button.PointY = myMousePt.y(); signals.onMouseUp->emit(myStEvent.Button); } break; } case AMOTION_EVENT_ACTION_MOVE: { myStEvent.Type = stEvent_TouchMove; if(aNbTouches == 1) { // simulate mouse move myMousePt = aPos0; myIsPreciseCursor = false; } doTouch(myStEvent.Touch); break; } case AMOTION_EVENT_ACTION_UP: case AMOTION_EVENT_ACTION_POINTER_UP: { myStEvent.Type = stEvent_TouchUp; doTouch(myStEvent.Touch); if(aNbTouches == 1) { // simulate mouse unclick myMousePt = aPos0; myIsPreciseCursor = false; myStEvent.Type = stEvent_MouseUp; myStEvent.Button.Button = ST_MOUSE_LEFT; myStEvent.Button.Buttons = 0; myStEvent.Button.PointX = myMousePt.x(); myStEvent.Button.PointY = myMousePt.y(); signals.onMouseUp->emit(myStEvent.Button); } break; } case AMOTION_EVENT_ACTION_CANCEL: { myStEvent.Type = stEvent_TouchCancel; doTouch(myStEvent.Touch); break; } } return; } } myMousePt = aPos0; myIsPreciseCursor = aSource == AINPUT_SOURCE_MOUSE; // || AINPUT_SOURCE_STYLUS StVirtButton aMouseBtn = ST_MOUSE_LEFT; myStEvent.Button.Button = aMouseBtn; myStEvent.Button.Buttons = 0; myStEvent.Button.PointX = myMousePt.x(); myStEvent.Button.PointY = myMousePt.y(); if(anAction == AMOTION_EVENT_ACTION_DOWN) { myStEvent.Type = stEvent_MouseDown; signals.onMouseDown->emit(myStEvent.Button); } else if(anAction == AMOTION_EVENT_ACTION_UP) { myStEvent.Type = stEvent_MouseUp; signals.onMouseUp->emit(myStEvent.Button); } return; } } }
static void android_input_poll(void *data) { (void)data; RARCH_PERFORMANCE_INIT(input_poll); RARCH_PERFORMANCE_START(input_poll); bool debug_enable = g_settings.input.debug_enable; struct android_app* android_app = (struct android_app*)g_android; uint64_t *lifecycle_state = &g_extern.lifecycle_state; *lifecycle_state &= ~((1ULL << RARCH_RESET) | (1ULL << RARCH_REWIND) | (1ULL << RARCH_FAST_FORWARD_KEY) | (1ULL << RARCH_FAST_FORWARD_HOLD_KEY) | (1ULL << RARCH_MUTE) | (1ULL << RARCH_SAVE_STATE_KEY) | (1ULL << RARCH_LOAD_STATE_KEY) | (1ULL << RARCH_STATE_SLOT_PLUS) | (1ULL << RARCH_STATE_SLOT_MINUS)); // Read all pending events. while (AInputQueue_hasEvents(android_app->inputQueue) > 0) { AInputEvent* event = NULL; if (AInputQueue_getEvent(android_app->inputQueue, &event) < 0) break; bool long_msg_enable = false; int32_t handled = 1; int action = 0; char msg[128]; msg[0] = 0; int source = AInputEvent_getSource(event); int id = AInputEvent_getDeviceId(event); if (id == zeus_second_id) id = zeus_id; int keycode = AKeyEvent_getKeyCode(event); int type_event = AInputEvent_getType(event); int state_id = -1; if (source & (AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_TOUCHPAD)) state_id = 0; // touch overlay is always player 1 else { for (unsigned i = 0; i < pads_connected; i++) if (state_device_ids[i] == id) state_id = i; } if (state_id < 0) { state_id = pads_connected; state_device_ids[pads_connected++] = id; input_autodetect_setup(android_app, msg, sizeof(msg), state_id, id, source); long_msg_enable = true; } if (keycode == AKEYCODE_BACK ) { int meta = AKeyEvent_getMetaState(event); if (!(meta & AMETA_ALT_ON)) { *lifecycle_state |= (1ULL << RARCH_QUIT_KEY); AInputQueue_finishEvent(android_app->inputQueue, event, handled); break; } } if (type_event == AINPUT_EVENT_TYPE_MOTION) { float x = 0.0f; float y = 0.0f; action = AMotionEvent_getAction(event); size_t motion_pointer = action >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT; action &= AMOTION_EVENT_ACTION_MASK; if (source & ~(AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_MOUSE)) { if (g_settings.input.dpad_emulation[state_id] != DPAD_EMULATION_NONE) { uint64_t *state_cur = &state[state_id]; x = AMotionEvent_getX(event, motion_pointer); y = AMotionEvent_getY(event, motion_pointer); *state_cur &= ~((1ULL << RETRO_DEVICE_ID_JOYPAD_LEFT) | (1ULL << RETRO_DEVICE_ID_JOYPAD_RIGHT) | (1ULL << RETRO_DEVICE_ID_JOYPAD_UP) | (1ULL << RETRO_DEVICE_ID_JOYPAD_DOWN)); *state_cur |= PRESSED_LEFT(x, y) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0; *state_cur |= PRESSED_RIGHT(x, y) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0; *state_cur |= PRESSED_UP(x, y) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_UP) : 0; *state_cur |= PRESSED_DOWN(x, y) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0; } } else { bool keyup = (action == AMOTION_EVENT_ACTION_UP || action == AMOTION_EVENT_ACTION_CANCEL || action == AMOTION_EVENT_ACTION_POINTER_UP) || (source == AINPUT_SOURCE_MOUSE && action != AMOTION_EVENT_ACTION_DOWN); if (keyup && motion_pointer < MAX_TOUCH) { memmove(pointer + motion_pointer, pointer + motion_pointer + 1, (MAX_TOUCH - motion_pointer - 1) * sizeof(struct input_pointer)); if (pointer_count > 0) pointer_count--; } else { int pointer_max = min(AMotionEvent_getPointerCount(event), MAX_TOUCH); for (motion_pointer = 0; motion_pointer < pointer_max; motion_pointer++) { x = AMotionEvent_getX(event, motion_pointer); y = AMotionEvent_getY(event, motion_pointer); input_translate_coord_viewport(x, y, &pointer[motion_pointer].x, &pointer[motion_pointer].y, &pointer[motion_pointer].full_x, &pointer[motion_pointer].full_y); pointer_count = max(pointer_count, motion_pointer + 1); } } } if (debug_enable) snprintf(msg, sizeof(msg), "Pad %d : x = %.2f, y = %.2f, src %d.\n", state_id, x, y, source); } else if (type_event == AINPUT_EVENT_TYPE_KEY)
/** * Process the next input event. */ static int32_t engine_handle_input( struct android_app* app, AInputEvent* event ) { JNIEnv *jni; (*jVM)->AttachCurrentThread(jVM, &jni, NULL); struct ENGINE* engine = (struct ENGINE*)app->userData; if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_KEY){ int device = AInputEvent_getDeviceId(event); int action = AKeyEvent_getAction(event); int keyCode = AKeyEvent_getKeyCode(event); if(jni && g_pActivity){ if((*jni)->ExceptionCheck(jni)) { (*jni)->ExceptionDescribe(jni); (*jni)->ExceptionClear(jni); } (*jni)->CallIntMethod(jni, g_pActivity, javaOnNDKKey, device, keyCode, action, AKeyEvent_getMetaState(event)); if (!(keyCode == AKEYCODE_MENU || keyCode == AKEYCODE_BACK || keyCode == AKEYCODE_BUTTON_THUMBR || keyCode == AKEYCODE_VOLUME_UP || keyCode == AKEYCODE_VOLUME_DOWN || keyCode == AKEYCODE_BUTTON_SELECT)) { return 1; } } } else if( AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION ) { int device = AInputEvent_getDeviceId( event ); int nSourceId = AInputEvent_getSource( event ); int nPointerCount = AMotionEvent_getPointerCount( event ); int n; jboolean newTouch = JNI_TRUE; for( n = 0 ; n < nPointerCount ; ++n ) { int nPointerId = AMotionEvent_getPointerId( event, n ); int nAction = AMOTION_EVENT_ACTION_MASK & AMotionEvent_getAction( event ); int nRawAction = AMotionEvent_getAction( event ); struct TOUCHSTATE *touchstate = 0; if( nSourceId == AINPUT_SOURCE_TOUCHPAD ) { touchstate = engine->touchstate_pad; } else { touchstate = engine->touchstate_screen; } if( nAction == AMOTION_EVENT_ACTION_POINTER_DOWN || nAction == AMOTION_EVENT_ACTION_POINTER_UP ) { int nPointerIndex = (AMotionEvent_getAction( event ) & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT; nPointerId = AMotionEvent_getPointerId( event, nPointerIndex ); } if( nAction == AMOTION_EVENT_ACTION_DOWN || nAction == AMOTION_EVENT_ACTION_POINTER_DOWN ) { touchstate[nPointerId].down = 1; } else if( nAction == AMOTION_EVENT_ACTION_UP || nAction == AMOTION_EVENT_ACTION_POINTER_UP || nAction == AMOTION_EVENT_ACTION_CANCEL ) { touchstate[nPointerId].down = 0; } if (touchstate[nPointerId].down == 1) { touchstate[nPointerId].x = AMotionEvent_getX( event, n ); touchstate[nPointerId].y = AMotionEvent_getY( event, n ); } if( jni && g_pActivity && isXperiaPlay) { // (*jni)->CallVoidMethod( jni, g_pActivity, javaOnNDKTouch, device, nSourceId, nRawAction, touchstate[nPointerId].x, touchstate[nPointerId].y, newTouch); (*jni)->CallVoidMethod( jni, g_pActivity, javaOnNDKTouch, device, nSourceId, nRawAction, touchstate[nPointerId].x, touchstate[nPointerId].y); } newTouch = JNI_FALSE; }
static void android_input_poll(void *data) { (void)data; RARCH_PERFORMANCE_INIT(input_poll); RARCH_PERFORMANCE_START(input_poll); struct android_app* android_app = g_android.app; g_extern.lifecycle_state &= ~((1ULL << RARCH_RESET) | (1ULL << RARCH_REWIND) | (1ULL << RARCH_FAST_FORWARD_KEY) | (1ULL << RARCH_FAST_FORWARD_HOLD_KEY) | (1ULL << RARCH_MUTE) | (1ULL << RARCH_SAVE_STATE_KEY) | (1ULL << RARCH_LOAD_STATE_KEY) | (1ULL << RARCH_STATE_SLOT_PLUS) | (1ULL << RARCH_STATE_SLOT_MINUS)); // Read all pending events. while(AInputQueue_hasEvents(android_app->inputQueue)) { AInputEvent* event = NULL; AInputQueue_getEvent(android_app->inputQueue, &event); if (AInputQueue_preDispatchEvent(android_app->inputQueue, event)) continue; int32_t handled = 1; int source = AInputEvent_getSource(event); int id = AInputEvent_getDeviceId(event); int type_event = AInputEvent_getType(event); int state_id = state_device_ids[id]; if(state_id == -1) state_id = state_device_ids[id] = pads_connected++; int action = 0; #ifdef RARCH_INPUT_DEBUG char msg[128]; #endif if(type_event == AINPUT_EVENT_TYPE_MOTION) { action = AMotionEvent_getAction(event); int8_t motion_action = action & AMOTION_EVENT_ACTION_MASK; size_t motion_pointer = action >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT; float x = AMotionEvent_getX(event, motion_pointer); float y = AMotionEvent_getY(event, motion_pointer); if(source & ~(AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_MOUSE)) { state[state_id] &= ~((1ULL << RETRO_DEVICE_ID_JOYPAD_LEFT) | (1ULL << RETRO_DEVICE_ID_JOYPAD_RIGHT) | (1ULL << RETRO_DEVICE_ID_JOYPAD_UP) | (1ULL << RETRO_DEVICE_ID_JOYPAD_DOWN)); state[state_id] |= PRESSED_LEFT(x, y) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0; state[state_id] |= PRESSED_RIGHT(x, y) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0; state[state_id] |= PRESSED_UP(x, y) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_UP) : 0; state[state_id] |= PRESSED_DOWN(x, y) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0; } else { bool mouse_is_not_dirty = (source == AINPUT_SOURCE_MOUSE && action != AMOTION_EVENT_ACTION_DOWN); bool pointer_is_not_dirty = (action == AMOTION_EVENT_ACTION_UP || action == AMOTION_EVENT_ACTION_CANCEL || action == AMOTION_EVENT_ACTION_POINTER_UP); pointer_dirty = !(mouse_is_not_dirty || pointer_is_not_dirty); if (pointer_dirty) input_translate_coord_viewport(x, y, &pointer_x, &pointer_y); } #ifdef RARCH_INPUT_DEBUG snprintf(msg, sizeof(msg), "Pad %d : x = %.2f, y = %.2f, src %d.\n", state_id, x, y, source); #endif } else {
static int32_t engine_handle_input(struct android_app* app, AInputEvent* event) { struct engineState* engine = (struct engineState*)app->userData; if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION) { int source = AInputEvent_getSource(event); if (source == AINPUT_SOURCE_TOUCHSCREEN) { float x = AMotionEvent_getX(event, 0); float y = AMotionEvent_getY(event, 0); engine->instance->getAndroidInputSystem()->handleTouchInput(x, y); return 1; } if (source == AINPUT_SOURCE_JOYSTICK) { float x = AMotionEvent_getAxisValue(event, AMOTION_EVENT_AXIS_X, 0); float y = AMotionEvent_getAxisValue(event, AMOTION_EVENT_AXIS_Y, 0); int devId = AInputEvent_getDeviceId(event); LOG_INFO("dev: " << devId << " pos: " << x << ":" << y); } return 0; } if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_KEY) { int32_t source = AInputEvent_getSource(event); int32_t code = AKeyEvent_getKeyCode(event); int32_t action = AKeyEvent_getAction(event); LOG_INFO("Code: " << code << " Action: " << action); engine::input::KeyCode keycode = engine::input::KEY_VOID; switch (code) { case 96: keycode = engine::input::BUTTON_A; break; case 99: keycode = engine::input::BUTTON_X; break; case 100: keycode = engine::input::BUTTON_Y; break; case 97: keycode = engine::input::BUTTON_B; break; } if (action == 1) engine->instance->getInputSystem()->keyUp(keycode); else engine->instance->getInputSystem()->keyDown(keycode); return 1; } return 0; }
//Called from the event process thread static int32_t HandleInputCB(struct android_app* app, AInputEvent* event) { // FPlatformMisc::LowLevelOutputDebugStringf(L"INPUT - type: %x, action: %x, source: %x, keycode: %x, buttons: %x", AInputEvent_getType(event), // AMotionEvent_getAction(event), AInputEvent_getSource(event), AKeyEvent_getKeyCode(event), AMotionEvent_getButtonState(event)); if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION) { int action = AMotionEvent_getAction(event); int actionType = action & AMOTION_EVENT_ACTION_MASK; size_t actionPointer = (size_t)((action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT); bool isActionTargeted = (actionType == AMOTION_EVENT_ACTION_POINTER_DOWN || actionType == AMOTION_EVENT_ACTION_POINTER_UP); // trap Joystick events first, with fallthrough if there is no joystick support if (((AInputEvent_getSource(event) & AINPUT_SOURCE_CLASS_JOYSTICK) != 0) && (GetAxes != NULL) && (actionType == AMOTION_EVENT_ACTION_MOVE)) { const int axisCount = sizeof(AxisList)/sizeof(int32_t); int device = AInputEvent_getDeviceId(event); for (int axis = 0; axis < axisCount; axis++) { float val = GetAxes( event, AxisList[axis], 0); FAndroidInputInterface::JoystickAxisEvent( device, AxisList[axis], val); } } else { TArray<TouchInput> TouchesArray; TouchType type = TouchEnded; switch (actionType) { case AMOTION_EVENT_ACTION_DOWN: case AMOTION_EVENT_ACTION_POINTER_DOWN: type = TouchBegan; break; case AMOTION_EVENT_ACTION_MOVE: type = TouchMoved; break; case AMOTION_EVENT_ACTION_UP: case AMOTION_EVENT_ACTION_POINTER_UP: case AMOTION_EVENT_ACTION_CANCEL: case AMOTION_EVENT_ACTION_OUTSIDE: type = TouchEnded; break; } size_t pointerCount = AMotionEvent_getPointerCount(event); if (pointerCount == 0) { return 1; } ANativeWindow* Window = (ANativeWindow*)FPlatformMisc::GetHardwareWindow(); if (!Window) { return 0; } int32_t Width = 0 ; int32_t Height = 0 ; if(Window) { FAndroidWindow::CalculateSurfaceSize(Window, Width, Height); } // make sure OpenGL context created before accepting touch events.. FAndroidWindow::GetScreenRect() may try to create it early from wrong thread if this is the first call if (!GAndroidGPUInfoReady) { return 1; } FPlatformRect ScreenRect = FAndroidWindow::GetScreenRect(); if(isActionTargeted) { if(actionPointer < 0 || pointerCount < (int)actionPointer) { return 1; } int pointerId = AMotionEvent_getPointerId(event, actionPointer); float x = FMath::Min<float>(AMotionEvent_getX(event, actionPointer) / Width, 1.f); x *= (ScreenRect.Right - 1); float y = FMath::Min<float>(AMotionEvent_getY(event, actionPointer) / Height, 1.f); y *= (ScreenRect.Bottom - 1); UE_LOG(LogAndroid, Verbose, TEXT("Received targeted motion event from pointer %u (id %d) action %d: (%.2f, %.2f)"), actionPointer, pointerId, action, x, y); TouchInput TouchMessage; TouchMessage.Handle = pointerId; TouchMessage.Type = type; TouchMessage.Position = FVector2D(x, y); TouchMessage.LastPosition = FVector2D(x, y); //@todo android: AMotionEvent_getHistoricalRawX TouchesArray.Add(TouchMessage); } else { for (size_t i = 0; i < pointerCount; ++i) { int pointerId = AMotionEvent_getPointerId(event, i); float x = FMath::Min<float>(AMotionEvent_getX(event, i) / Width, 1.f); x *= (ScreenRect.Right - 1); float y = FMath::Min<float>(AMotionEvent_getY(event, i) / Height, 1.f); y *= (ScreenRect.Bottom - 1); UE_LOG(LogAndroid, Verbose, TEXT("Received motion event from pointer %u (id %d) action %d: (%.2f, %.2f)"), i, action, AMotionEvent_getPointerId(event,i), x, y); TouchInput TouchMessage; TouchMessage.Handle = AMotionEvent_getPointerId(event, i); TouchMessage.Type = type; TouchMessage.Position = FVector2D(x, y); TouchMessage.LastPosition = FVector2D(x, y); //@todo android: AMotionEvent_getHistoricalRawX TouchesArray.Add(TouchMessage); } } FAndroidInputInterface::QueueTouchInput(TouchesArray); #if !UE_BUILD_SHIPPING if ((pointerCount >= 4) && (type == TouchBegan)) { bool bShowConsole = true; GConfig->GetBool(TEXT("/Script/Engine.InputSettings"), TEXT("bShowConsoleOnFourFingerTap"), bShowConsole, GInputIni); if (bShowConsole) { GShowConsoleWindowNextTick = true; } } #endif } return 1; }