A sample text widget

Etiam pulvinar consectetur dolor sed malesuada. Ut convallis euismod dolor nec pretium. Nunc ut tristique massa.

Nam sodales mi vitae dolor ullamcorper et vulputate enim accumsan. Morbi orci magna, tincidunt vitae molestie nec, molestie at mi. Nulla nulla lorem, suscipit in posuere in, interdum non magna.

Screen Knock!

screenknock.zip

The fabled screen knock software is here.
Yes, it hit me one day that I could simply have
the motion sensor move the spaces. The interaction
was amusing and I’m hoping you’ll think so too.

  1.  
  2. // Screen Knock Version 1
  3. // October 1, 2008
  4. // by Chris Stones
  5. // http://www.welcometochrisworld.com
  6. //
  7. // One of the few programs I pretty much wrote from skratch.
  8. // Special thanks to the SMS Lib though by Daniel Shiffman and others
  9. // Note: Spaces on Mac OS 10.5 needs to be set to use
  10. // Command + Arrow Keys for this program to work.
  11. // * For best performance customize
  12. // KNOCK and wait_for_shake to your system.
  13. // as in ... you know, use trail and error values until you get it right.
  14.  
  15. // I had always acted out like I was knocking my laptop
  16. // from one space to the next. But I finally sat down and made
  17. // it do it by itself.
  18.  
  19. import java.awt.Robot;
  20. import java.awt.event.KeyEvent;
  21. import sms.*; // Sudden motion detection
  22.  
  23. Robot robot;
  24. int[] init_vals;
  25. int[] vals;
  26. int KNOCK;
  27. int wait_for_shake;
  28. boolean wait;
  29. int wait_cnt;
  30.  
  31. int X,Y,Z; // calculated thresholds
  32.  
  33. void setup() {
  34. size(100,100);
  35. frameRate(20);
  36. wait = false;
  37. wait_cnt = 0;
  38. wait_for_shake = 15; // wait for shaking to stop (number/frames = seconds of waiting)
  39. KNOCK = 15; // How big of a jolt before you want to move the screen
  40. try {
  41. robot = new Robot();
  42. }
  43. catch (Exception e) {
  44. println("robot Can not be created.");
  45. exit();
  46. }
  47.  
  48. // Opening values don't start at zero.
  49. // So we need to collect values at 'rest'
  50. init_vals = Unimotion.getSMSArray();
  51.  
  52. X = init_vals[0];
  53. Y = init_vals[1];
  54. Z = init_vals[2];
  55. }
  56.  
  57.  
  58. void draw() {
  59. // Read Sudden Motion Sensor
  60. int[] vals = Unimotion.getSMSArray();
  61.  
  62. // Reset wait count to allow another jolt
  63. if( wait_cnt == wait_for_shake) {
  64. wait = false;
  65. wait_cnt = 0;
  66. }
  67.  
  68. // While we are not waiting for the computer to
  69. // stop shaking try to make a decision about
  70. // the motion.
  71. if(!wait) {
  72.  
  73. // There's always some shaking going on so we
  74. // need to check if the shaking was on purpose.
  75. if( vals[0] > KNOCK+X ) {
  76. screenLeft();
  77. wait = true;
  78. }
  79.  
  80. if( vals[0] < -1*KNOCK+X ) {
  81. screenRight();
  82. wait = true;
  83. }
  84.  
  85. }
  86. else {
  87. wait_cnt++;
  88. }
  89.  
  90.  
  91. }
  92.  
  93. void screenRight() {
  94. try {
  95. robot.keyPress(KeyEvent.VK_META); // hold meta
  96. robot.keyPress(KeyEvent.VK_RIGHT ); // then press arrow
  97. robot.keyRelease(KeyEvent.VK_META);
  98. robot.keyRelease(KeyEvent.VK_RIGHT);
  99. }
  100. catch (Exception e) {
  101. println("Exception your honor!");
  102. }
  103. }
  104.  
  105. void screenLeft() {
  106. try {
  107. robot.keyPress(KeyEvent.VK_META); // hold meta
  108. robot.keyPress(KeyEvent.VK_LEFT ); // then press arrow
  109. robot.keyRelease(KeyEvent.VK_META);
  110. robot.keyRelease(KeyEvent.VK_LEFT);
  111. }
  112. catch (Exception e) {
  113. println("Exception your honor!");
  114. }
  115. }
  116.  
  117. void screenUp() {
  118. try {
  119. robot.keyPress(KeyEvent.VK_META); // hold meta
  120. robot.keyPress(KeyEvent.VK_UP ); // then press arrow
  121. robot.keyRelease(KeyEvent.VK_META);
  122. robot.keyRelease(KeyEvent.VK_UP);
  123. }
  124. catch (Exception e) {
  125. println("Exception your honor!");
  126. }
  127. }
  128.  
  129.  
  130. void screenDown() {
  131. try {
  132. robot.keyPress(KeyEvent.VK_META); // hold meta
  133. robot.keyPress(KeyEvent.VK_DOWN ); // then press arrow
  134. robot.keyRelease(KeyEvent.VK_META);
  135. robot.keyRelease(KeyEvent.VK_DOWN);
  136. }
  137. catch (Exception e) {
  138. println("Exception your honor!");
  139. }
  140. }
  141.  
  142.  

12 comments to Screen Knock!

Leave a Reply