+ This is a simple example of how to implement Pebble button clicks in RockyJS using a keyboard's directional arrow keys.
+
+
+
+
+
+
+
+
+
What's going on?
+
+ This example demonstrates how to interact with RockyJS bound to a canvas. Using the left, right, up, and down arrows on your keyboard you can simulate the back, select, up, and down buttons of the Pebble respectively.
+
+
+ rocky.onPress(type, callback)
+
+ Options for type are 'back', 'select', 'up', or 'down'.
+
+
+ Source for this example can be found at [link TBD].
+
+
+
+
+
+
diff --git a/examples/readme.md b/examples/readme.md
index 454885e..9317a41 100644
--- a/examples/readme.md
+++ b/examples/readme.md
@@ -8,5 +8,6 @@ This folder contains a variety of examples designed to help you understand some
- [Vector Graphics](pdc/index.html) – Draws and modifies vector graphics.
- [GPath](gpath/index.html) – Shows how to use APIs around `GPath`.
- [Text](text/index.html) – Shows how to draw text and use fonts.
+ - [Buttons](buttons/index.html) - Shows how to interact using keyboard arrows.
- [Community Examples](community.html) - Additional examples built by community members.
diff --git a/src/symbols-manual.js b/src/symbols-manual.js
index 58f66cc..7381973 100644
--- a/src/symbols-manual.js
+++ b/src/symbols-manual.js
@@ -462,6 +462,24 @@ Rocky.addManualSymbols = function(obj) {
});
};
+ obj.buttonHandler = {};
+
+ obj.onPress = function onPress(type, callback) {
+ this.buttonHandler[type] = callback;
+ };
+
+ document.addEventListener('keydown', function(event) {
+ if (event.keyCode === 37 && obj.buttonHandler.back) {
+ obj.buttonHandler['back'].bind(obj)();
+ } else if (event.keyCode === 38 && obj.buttonHandler.up) {
+ obj.buttonHandler['up'].bind(obj)();
+ } else if (event.keyCode === 39 && obj.buttonHandler.select) {
+ obj.buttonHandler['select'].bind(obj)();
+ } else if (event.keyCode === 40 && obj.buttonHandler.down) {
+ obj.buttonHandler['down'].bind(obj)();
+ }
+ });
+
return ['Data', 'Resources'];
};
From db03cd871557c084d7caf0332bd8628ea18986ee Mon Sep 17 00:00:00 2001
From: Katherine McAuliffe
Date: Wed, 10 Feb 2016 15:07:00 -0800
Subject: [PATCH 2/5] change integrated API to module
---
examples/buttons/index.html | 20 +++++++++++---------
examples/buttons/modules/buttons.js | 19 +++++++++++++++++++
src/symbols-manual.js | 18 ------------------
3 files changed, 30 insertions(+), 27 deletions(-)
create mode 100644 examples/buttons/modules/buttons.js
diff --git a/examples/buttons/index.html b/examples/buttons/index.html
index 9ac3925..61aa517 100644
--- a/examples/buttons/index.html
+++ b/examples/buttons/index.html
@@ -18,6 +18,8 @@
+
+
@@ -53,7 +55,7 @@
What's going on?
This example demonstrates how to interact with RockyJS bound to a canvas. Using the left, right, up, and down arrows on your keyboard you can simulate the back, select, up, and down buttons of the Pebble respectively.