23.01.2018 Views

MICROSOFT_PRESS_EBOOK_PROGRAMMING_WINDOWS_8_APPS_WITH_HTML_CSS_AND_JAVASCRIPT_PDF

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Again, refer to the documentation on Windows.UI.Input.GestureRecognizer for all the details and<br />

refer to the sample for some bits of code. As one extra example, here’s a snippet to capture a small<br />

horizontal motion using the manipuationTranslateX setting:<br />

var recognizer = new Windows.UI.Input.GestureRecognizer();<br />

recognizer.gestureSettings = Windows.UI.Input.GestureSettings.manipulationTranslateX;<br />

var DELTA = 10;<br />

myElement.addEventListener('MSPointerDown', function (e) {<br />

recognizer.processDownEvent(e.getCurrentPoint(e.pointerId));<br />

});<br />

myElement.addEventListener('MSPointerUp', function (e) {<br />

recognizer.processUpEvent(e.getCurrentPoint(e.pointerId));<br />

});<br />

myElement.addEventListener('MSPointerMove', function (e) {<br />

recognizer.processMoveEvents(e.getIntermediatePoints(e.pointerId));<br />

});<br />

// Remember removeEventListener as needed for this event<br />

recognizer.addEventListener('manipulationcompleted', function (args) {<br />

var pt = args.cumulative.translation;<br />

if (pt.x < -DELTA) {<br />

// move right<br />

}<br />

else if (pt.x > DELTA) {<br />

// move left<br />

}<br />

});<br />

Beyond the recognizer, do note that you can always go the low-level route and do your own<br />

processing of MSPointer* events however you want, completely bypassing the gesture recognizer. This<br />

would be necessary if the configurations allowed by the recognizer object don’t accommodate your<br />

specific need. At the same time, now is a good opportunity to re-read “Sidebar: Creating Completely<br />

New Gesture?” at the end of the earlier section on the touch language. It addresses a few of the<br />

questions about when and if custom gestures are really needed.<br />

Keyboard Input and the Soft Keyboard<br />

After everything to do with touch and other forms of input, it seems almost anticlimactic to consider the<br />

humble keyboard. Yet of course the keyboard remains utterly important for textual input, whether it’s a<br />

physical key-board or the on-screen “soft” keyboard. It is especially important for accessibility as well, as<br />

some users are physically unable to use a mouse or other devices. In fact, the Windows 8 app<br />

certification requirements (section 3.5) make keyboard input mandatory.<br />

Fortunately, there is nothing special about handling keyboard input in a Windows Store app, but a<br />

little goes a long way. Drawing from Implementing keyboard accessibility, here’s a summary:<br />

388

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!