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 Your Application

The client sends inputs to the application through several methods, depending on the input type.

The following excerpt from the example client in the Amazon AppStream SDK illustrates a method that sends motion inputs to the application. The excerpt is from the dispatchGenericMotionEvent method in SampleClientActivity.java.

Copy
public boolean dispatchGenericMotionEvent (MotionEvent event) { if (event.getSource()==InputDevice.SOURCE_MOUSE) { event.getPointerCoords(0, mCoordHolder); switch (event.getAction()) { case MotionEvent.ACTION_HOVER_MOVE : AppStreamInterface.mouseEvent((int)mCoordHolder.x,(int)mCoordHolder.y, 0); break; default: return super.dispatchGenericMotionEvent(event); } return true; } else if (event.getSource()==InputDevice.SOURCE_JOYSTICK && event.getAction() == MotionEvent.ACTION_MOVE) { Log.v(TAG,"Joystick event:"+event.toString()); /// @todo: Handle motion event return true; } return super.dispatchGenericMotionEvent(event); }

The following excerpt from the example client in the Amazon AppStream SDK illustrates a method that sends touch inputs to the application. The excerpt is from the dispatchTouchEvent method in SampleClientActivity.java.

Copy
public boolean dispatchTouchEvent (MotionEvent event) { if (mScaleGestureDetector.onTouchEvent(event)) { if (mScaleGestureDetector.isInProgress()) return true; } int flags = 0; if (event.getSource()==InputDevice.SOURCE_TOUCHSCREEN) { flags = AppStreamInterface.CET_TOUCH_FLAG ; } event.getPointerCoords(0, mCoordHolder); switch (event.getAction()) { case MotionEvent.ACTION_MOVE : AppStreamInterface.mouseEvent((int)mCoordHolder.x,(int)mCoordHolder.y, flags); break; case MotionEvent.ACTION_DOWN : AppStreamInterface.mouseEvent((int)mCoordHolder.x,(int)mCoordHolder.y, AppStreamInterface.CET_MOUSE_1_DOWN|flags); break; case MotionEvent.ACTION_UP : AppStreamInterface.mouseEvent((int)mCoordHolder.x,(int)mCoordHolder.y, AppStreamInterface.CET_MOUSE_1_UP|flags); AppStreamInterface.mouseEvent((int)-1000,(int)-1000, flags); break; default: return super.dispatchGenericMotionEvent(event); } return super.dispatchTouchEvent(event); }

The following excerpt from the example client in the Amazon AppStream SDK illustrates methods that sends key inputs to the application. The excerpt is from SampleClientActivity.java.

Copy
private void onKey(KeyEvent msg, boolean down) { int keyCode =msg.getKeyCode(); switch (keyCode) { case KeyEvent.KEYCODE_DPAD_RIGHT : AppStreamInterface.keyPress(0x27,down); break; case KeyEvent.KEYCODE_DPAD_LEFT : AppStreamInterface.keyPress(0x25,down); break; case KeyEvent.KEYCODE_DPAD_UP : AppStreamInterface.keyPress(0x26,down); break; case KeyEvent.KEYCODE_DPAD_DOWN : AppStreamInterface.keyPress(0x28,down); break; case KeyEvent.KEYCODE_FORWARD_DEL: AppStreamInterface.keyPress(0x2E,down); break; case KeyEvent.KEYCODE_DEL: AppStreamInterface.keyPress(0x08,down); break; case KeyEvent.KEYCODE_ALT_LEFT: AppStreamInterface.keyPress(0x12,down); AppStreamInterface.keyPress(0xA4,down); break; case KeyEvent.KEYCODE_ALT_RIGHT: AppStreamInterface.keyPress(0x12,down); AppStreamInterface.keyPress(0xA5,down); break; case KeyEvent.KEYCODE_CTRL_LEFT: AppStreamInterface.keyPress(0x11,down); AppStreamInterface.keyPress(0xA2,down); break; case KeyEvent.KEYCODE_CTRL_RIGHT: AppStreamInterface.keyPress(0x11,down); AppStreamInterface.keyPress(0xA3,down); break; case KeyEvent.KEYCODE_SHIFT_LEFT: AppStreamInterface.keyPress(0x10,down); AppStreamInterface.keyPress(0xA0,down); break; case KeyEvent.KEYCODE_SHIFT_RIGHT: AppStreamInterface.keyPress(0x10,down); AppStreamInterface.keyPress(0xA1,down); break; case KeyEvent.KEYCODE_APOSTROPHE: AppStreamInterface.keyPress('\'',down); break; case KeyEvent.KEYCODE_AT: AppStreamInterface.keyPress('@',down); break; case KeyEvent.KEYCODE_ENTER: AppStreamInterface.keyPress(0x0D,down); break; case KeyEvent.KEYCODE_BREAK: AppStreamInterface.keyPress(0x03,down); break; case KeyEvent.KEYCODE_VOLUME_UP: AppStreamInterface.keyPress(0xAF,down); break; case KeyEvent.KEYCODE_VOLUME_DOWN: AppStreamInterface.keyPress(0xAE,down); break; case KeyEvent.KEYCODE_MEDIA_NEXT: AppStreamInterface.keyPress(0xB0,down); break; case KeyEvent.KEYCODE_MEDIA_PREVIOUS: AppStreamInterface.keyPress(0xB1,down); break; case KeyEvent.KEYCODE_MEDIA_STOP: AppStreamInterface.keyPress(0xB2,down); break; case KeyEvent.KEYCODE_MEDIA_PLAY: AppStreamInterface.keyPress(0xFA,down); break; case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: AppStreamInterface.keyPress(0xB3,down); break; case KeyEvent.KEYCODE_ESCAPE: case KeyEvent.KEYCODE_BACK: AppStreamInterface.keyPress(0x1b,down); break; default: { String key = new String(Character.toString((char)msg.getUnicodeChar())); keyCode = key.toUpperCase(Locale.US).codePointAt(0); AppStreamInterface.keyPress(keyCode,down); } } } @Override public boolean onKeyDown(int keyCode, KeyEvent msg) { onKey(msg,true); return super.onKeyDown(keyCode, msg); } @Override public boolean onKeyUp(int keyCode, KeyEvent msg) { onKey(msg,false); return super.onKeyUp(keyCode, msg); }