Screen Knock!
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.
// Screen Knock Version 1 // October 1, 2008 // by Chris Stones // http://www.welcometochrisworld.com // // One of the few programs I pretty much wrote from skratch. // Special thanks to the SMS Lib though by Daniel Shiffman and others // Note: Spaces on Mac OS 10.5 needs to be set to use // Command + Arrow Keys for this program to work. // * For best performance customize // KNOCK and wait_for_shake to your system. // as in ... you know, use trail and error values until you get it right. // I had always acted out like I was knocking my laptop // from one space to the next. But I finally sat down and made // it do it by itself. import java.awt.Robot; import java.awt.event.KeyEvent; import sms.*; // Sudden motion detection Robot robot; int[] init_vals; int[] vals; int KNOCK; int wait_for_shake; boolean wait; int wait_cnt; int X,Y,Z; // calculated thresholds void setup() { size(100,100); frameRate(20); wait = false; wait_cnt = 0; wait_for_shake = 15; // wait for shaking to stop (number/frames = seconds of waiting) KNOCK = 15; // How big of a jolt before you want to move the screen try { robot = new Robot(); } catch (Exception e) { println("robot Can not be created."); exit(); } // Opening values don't start at zero. // So we need to collect values at 'rest' init_vals = Unimotion.getSMSArray(); X = init_vals[0]; Y = init_vals[1]; Z = init_vals[2]; } void draw() { // Read Sudden Motion Sensor int[] vals = Unimotion.getSMSArray(); // Reset wait count to allow another jolt if( wait_cnt == wait_for_shake) { wait = false; wait_cnt = 0; } // While we are not waiting for the computer to // stop shaking try to make a decision about // the motion. if(!wait) { // There's always some shaking going on so we // need to check if the shaking was on purpose. if( vals[0] > KNOCK+X ) { screenLeft(); wait = true; } if( vals[0] < -1*KNOCK+X ) { screenRight(); wait = true; } } else { wait_cnt++; } } void screenRight() { try { robot.keyPress(KeyEvent.VK_META); // hold meta robot.keyPress(KeyEvent.VK_RIGHT ); // then press arrow robot.keyRelease(KeyEvent.VK_META); robot.keyRelease(KeyEvent.VK_RIGHT); } catch (Exception e) { println("Exception your honor!"); } } void screenLeft() { try { robot.keyPress(KeyEvent.VK_META); // hold meta robot.keyPress(KeyEvent.VK_LEFT ); // then press arrow robot.keyRelease(KeyEvent.VK_META); robot.keyRelease(KeyEvent.VK_LEFT); } catch (Exception e) { println("Exception your honor!"); } } void screenUp() { try { robot.keyPress(KeyEvent.VK_META); // hold meta robot.keyPress(KeyEvent.VK_UP ); // then press arrow robot.keyRelease(KeyEvent.VK_META); robot.keyRelease(KeyEvent.VK_UP); } catch (Exception e) { println("Exception your honor!"); } } void screenDown() { try { robot.keyPress(KeyEvent.VK_META); // hold meta robot.keyPress(KeyEvent.VK_DOWN ); // then press arrow robot.keyRelease(KeyEvent.VK_META); robot.keyRelease(KeyEvent.VK_DOWN); } catch (Exception e) { println("Exception your honor!"); } }
Neat stuff
Cool and it makes you HAPPY–so I’m happy.
I was thinking you were going to invent a KNOCK KNOCK sound instead of an invasive PING when email comes in!!! Would that be retro?
Love from ChrisMom
I remember you asking if I could see the videos you put up, and if there is one here then the answer is no.
thank you for this thing it very cool
any version of this for windows users?
hey.. what are you supposed to do with the zip? i can’t figure it out
Thanks, Chris for this fun piece of code..
Was googling for some information about Sudden Motion Sensor technology and found out you Screen Knock app. Very nice and smart :-)
By the way, your video is good :-)
thank you very much i really appreciate it.can you make another program that can expose too.cos your is easy to install thanks
How about a method to change the keypress to combination other than command+arrow.
How about converting screen knock to a menubar app?
Nice App btw.
Great App bud.
Not Good for my Macbook (Especially when its on my lap ha XD)
Good for my iMac Though.
Sick job, NIce Vid.
Does it work with Snow Leopard?! Doesn\\\’t even open in my macbook. thanks
how do u control which space is goes to seriously…