ADAM'S WEB PRESENCE

25 October 2006

Squiggly Wire Game

Filed under: Homemade Creations — adam @ 8:30 pm

Kai having fun with the Squiggly Wire gameThis week, Kai and I built an electronic game of skill out of a wire coat hanger.

You’ve probably seen this one before, the idea is to move a hoop along a bent wire without touching the wire. If you touch the wire, a buzzer sounds and you have to start again.

We built ours out of an old plastic box which once contained chocolate. A wire coat hanger was the main component. I cut off a few inches of the coat hanger to bend into a loop and used the rest to make the squiggly wire. The ends of the wire were bent into tight loops through which I put small bolts to secure it to the box.

The electronics and battery holder were simply glued to the inside of the box using hot-glue which is really an incredibly useful substance.

After I soldered a flexible wire to the loop, Kai put some bicycle handlebar tape around it to make the grip. For strain relief on the wire, I used a cable-tie.

The end of the wire is a yellow “safe zone” which was made simply by wrapping electrical tape around the wire to prevent electrical contact.


Squiggly Wire Game SchematicThe noise maker

I didn’t have a buzzer handy but I did have a 555 timer chip so I used it to build an oscillator and connected that to a small piezo speaker in keeping with my principle of using whatever parts I’ve already got wherever possible.

Much has been written about the 555 timer IC. I have wired mine in the classic astable mode. The values of the components are not at all critical, the formula below shows how to compute the output frequency from the component values. The 100µF capacitor was added to provide a little sustain so that the sound is less “scratchy” when the wire is touched lightly.

Of course, if you are not a complete nerd, you would probably just get a buzzer.

How to compute the output frequency of an NE555
Formula to calculate the output frequency

The result

I was going to paint the box but my wife (who is an artist) said “Noooo! it looks so post-modern in clear plastic with the chocolate label still on it” - so it has stayed un-painted.

This has cost me $0. It is built completely from parts I have found around the house. I like the challenge of trying to use what I have and this project completely achieves that goal. Here are some more photos:


Building the circuit onto veroboard Kai helping to build it The finished article


10 October 2006

Sending fake keypress events to an X11 window

Filed under: Bizarre Stuff, Nerd Notes — adam @ 12:43 pm

This C++ example code will send a cursor-down event to the currently focussed window. It can easily be modified to send other key events. It would be a good starting point to write a virtual keyboard or remote control application.

// Send a fake keystroke event to an X window.
// by Adam Pierce - http://www.doctort.org/adam/
// This is public domain software. It is free to use by anyone for any purpose.

#include <X11/Xlib.h>
#include <X11/keysym.h>

// The key code to be sent.
// A full list of available codes can be found in /usr/include/X11/keysymdef.h
#define KEYCODE XK_Down

// Function to create a keyboard event
XKeyEvent createKeyEvent(Display *display, Window &win,
                           Window &winRoot, bool press,
                           int keycode, int modifiers)
{
   XKeyEvent event;

   event.display     = display;
   event.window      = win;
   event.root        = winRoot;
   event.subwindow   = None;
   event.time        = CurrentTime;
   event.x           = 1;
   event.y           = 1;
   event.x_root      = 1;
   event.y_root      = 1;
   event.same_screen = True;
   event.keycode     = XKeysymToKeycode(display, keycode);
   event.state       = modifiers;

   if(press)
      event.type = KeyPress;
   else
      event.type = KeyRelease;

   return event;
}

main()
{
// Obtain the X11 display.
   Display *display = XOpenDisplay(0);
   if(display == NULL)
      return -1;

// Get the root window for the current display.
   Window winRoot = XDefaultRootWindow(display);

// Find the window which has the current keyboard focus.
   Window winFocus;
   int    revert;
   XGetInputFocus(display, &winFocus, &revert);

// Send a fake key press event to the window.
   XKeyEvent event = createKeyEvent(display, winFocus, winRoot, true, KEYCODE, 0);
   XSendEvent(event.display, event.window, True, KeyPressMask, (XEvent *)&event);

// Send a fake key release event to the window.
   event = createKeyEvent(display, winFocus, winRoot, false, KEYCODE, 0);
   XSendEvent(event.display, event.window, True, KeyPressMask, (XEvent *)&event);

// Done.
   XCloseDisplay(display);
   return 0;
}

To compile it, you need to type this:

g++ -o XFakeKey XFakeKey.cpp -L/usr/X11R6/lib -lX11

Powered by WordPress