Menu
Amazon AppStream
Developer Guide

This documentation is for an older version of Amazon AppStream. For information about the latest version, see the Amazon AppStream 2.0 Developer Guide.

Sending Your Client Inputs to the Application

The client can send keyboard, mouse, touch, or raw inputs to the application. The client sends an input by filling out the XStxInputEvent structure that describes the input and then calling a function that passes the structure to the application.

The following excerpt from the example client in the Amazon AppStream SDK illustrates a keyboard action that populates the structures and then sending that structure to the application. The excerpt is from the keyChange function in DirectXRenderWindow.cpp.

Copy
/** Handles WM_KEYDOWN & WM_KEYUP messages. */ void keyChange(WPARAM wParam, LPARAM lParam, bool isKeyDown) { if (!mListener) { return; } XStxInputEvent inputEvent; inputEvent.mTimestampUs = mud::TimeVal::mono().toMicroSeconds(); inputEvent.mDeviceId = 0; inputEvent.mUserId = 0; inputEvent.mType = INPUT_EVENT_TYPE_KEYBOARD; inputEvent.mInfo.mKeyboard.mIsKeyDown = isKeyDown; inputEvent.mInfo.mKeyboard.mVirtualKey = wParam; inputEvent.mInfo.mKeyboard.mScanCode = lParam; inputEvent.mSize = sizeof(inputEvent); mListener->sendInput(inputEvent); }

The following excerpt from the example client in the Amazon AppStream SDK illustrates a mouse action that populates the structures and then sending that structure to the application. The excerpt is from the mouseChange function in DirectXRenderWindow.cpp.

Copy
void mouseChange(WPARAM wParam, LPARAM lParam, bool isDown, bool isLeft) { if (!mListener) { return; } XStxInputEvent inputEvent; inputEvent.mTimestampUs = mud::TimeVal::mono().toMicroSeconds(); inputEvent.mDeviceId = 0; inputEvent.mUserId = 0; inputEvent.mType = INPUT_EVENT_TYPE_MOUSE; inputEvent.mInfo.mMouse.mFlags = MOUSE_MOVE_ABSOLUTE; int32_t leftchange = 0; int32_t rightChange = 0; if (isLeft) { leftchange = isDown ? RI_MOUSE_LEFT_BUTTON_DOWN : RI_MOUSE_LEFT_BUTTON_UP; } else { rightChange = isDown ? RI_MOUSE_RIGHT_BUTTON_DOWN : RI_MOUSE_RIGHT_BUTTON_UP; } inputEvent.mInfo.mMouse.mButtonFlags = leftchange | rightChange; inputEvent.mInfo.mMouse.mButtons = 0;// not needed inputEvent.mInfo.mMouse.mButtonData = 0; // not sending wheel data rescaleMouseInput(lParam, inputEvent.mInfo.mMouse.mLastX, inputEvent.mInfo.mMouse.mLastY); inputEvent.mSize = sizeof(inputEvent); mListener->sendInput(inputEvent); }

If the client is a different size from the application, the client rescales the mouse position to adjust for the different sizes.

The following excerpt from the example client in the Amazon AppStream SDK illustrates this step. The excerpt is from the rescaleMouseInput function in DirectXRenderWindow.cpp.

Copy
/** Rescales absolute mouse position. */ void rescaleMouseInput(LPARAM lParam, int32_t & outX, int32_t & outY) { // if we send absolute input, we need to rescale it RECT desktopRect; GetWindowRect(mWindow, &desktopRect); float rescaleHeight = mLastSetHeight / (float) (desktopRect.bottom - desktopRect.top - mWindowBorderAdjustHeight); float rescaleWidth = mLastSetWidth / (float) (desktopRect.right - desktopRect.left - mWindowBorderAdjustWidth); outX = GET_X_LPARAM(lParam) * rescaleWidth + 0.5f; // add 0.5 for rounding outY = GET_Y_LPARAM(lParam) * rescaleHeight + 0.5f; }

Touch input is sent as a mouse action.