Fun with code (since 2006)

Mouse Gesture Recognition


05.11.07 Posted in Actionscript 3 by

I have worked yesterday on a simple implementation of a mouse gesture recognition algorithm.

Here's a demonstration.
Mouse Gesture
I'll probabaly publish a MouseGesture.as class soon, so stay tuned.

Mouse Gesture [ADD : 2007-05-17]

Open Source This project is OPEN SOURCE under RPL License.
2007-05-17 v1.0 mouse_gesture_v1_0.zip

The zip file contains the MouseGesture class + the full code of sample demo above.

Algorithm

Mouse Gesture Algorithm

  1. Each letter is defined by a n ' 8-directions gesture sequence
  2. The mouse moves are saved with the same 8-directions sensibility
  3. A Levenshtein distance is calculated from each letter to the user moves
  4. The algorithm return the best candidate (lowest levenshtein cost)

Usage

Example for the B :

gesture=new MouseGesture(stage);
gesture.addGesture("B","260123401234");
gesture.addEventListener(GestureEvent.MATCH,matchHandler);

function matchHandler(e:GestureEvent):void{
trace (e.datas+" matched !")
}



128 Responses to “Mouse Gesture Recognition”

  1. [...] 作者:http://www.bytearray.org/?p=91 ?View Code ACTIONSCRIPT3protected var mg:MouseGesture = null;   mg = new MouseGesture(this.stage); mg.addGesture("UP", "6"); mg.addGesture("DOWN", "2"); mg.addGesture("RIGHT", "0"); mg.addGesture("LEFT", "4"); mg.addGesture("CLOCK", "67012345"); mg.addGesture("ANTICLOCK", "65432107");   mg.addEventListener(GestureEvent.GESTURE_MATCH,matchHandler);   // 不同鼠标手势执行不同的处理 protected function matchHandler(event:GestureEvent):void { TweenMax.killAllTweens();   switch (event.datas) { case "UP": TweenMax.to(mesh, 1, {rotationX: mesh.rotationX – 360}); break; case "DOWN": TweenMax.to(mesh, 1, {rotationX: mesh.rotationX + 360}); break; case "LEFT": TweenMax.to(mesh, 1, {rotationY: mesh.rotationY + 360}); break; case "RIGHT": TweenMax.to(mesh, 1, {rotationY: mesh.rotationY – 360}); break; case "CLOCK": TweenMax.to(mesh, 1, {rotationZ: mesh.rotationZ + 360}); break; case "ANTICLOCK": TweenMax.to(mesh, 1, {rotationZ: mesh.rotationZ – 360}); break; } } [...]

     
  2. [...] mal hier Mouse Gesture Recognition <font size='1'>[ by Didier Brun aka Foxy ]</font> – ByteArray…. hoffe das [...]

     
  3. [...] into it, there is already a library in AS3 that’s really simple to use it and it works great. The Mouse Gesture Recognition lib for AS3, created by Didier Brun, implements all of the functionality that we need to detect mouse gestures; [...]

     
  4. [...] into it, there is already a library in AS3 that’s really simple to use it and it works great. The Mouse Gesture Recognition lib for AS3, created by Didier Brun, implements all of the functionality that we need to detect mouse gestures; [...]

     
  5. [...] second package I looked into was posted in a short article at ByteArray.org by Didier Brun. I caught this post when it first came out (almost three years ago) and was very impressed with the [...]

     
  6. Ahrengot says:

    Great stuff that’s fun to play with :)

    Just to clarify, the RPL license means i wouldn’t be able to sell any components that implement this class on say activeden.net or flashcomponents.net, right?

  7. Jeff Howard says:

    Hi Didier,

    This is a really excellent class and demo that fits very well with a project that I’m working on. Unfortunately, I can’t get the .fla file to play outside of your web page. The demo works fine on your web page above, but when I download the zip and publish the swf myself from the .fla file, the background image appears without allowing me to draw any gestures. I’m using Flash CS5. I wonder if I have my publish settings or any other settings configured incorrectly. Any help would be greatly appreciated.

  8. nadous says:

    Great work. I took it and did this : http://www.youtube.com/watch?v=xc7kA2yuKpM

  9. iPhone touch gesture says:

    Hi Didier,

    I am very interested to translate your code to objective-c for an iphone compatible version!
    What do you think?
    If you agree, I might need a few hints though, if you don’t mind…

  10. Rodney says:

    I think that this would be great as an admin/secret login module. If the user types in their info, then regular login, if they use mouse gestures, then they gain access to the admin section.

  11. puneet kalra says:

    How to implement this algorithm in objective c

  12. James says:

    Thank you very much for this. I will be using it in an upcoming game.

  13. acepharieliem says:

    Hello!
    I’ve recently augment
    a marvelous search league –
    <a href=praca kraków
    P.S. Yahoo – all will-power be drill! Google: nothing was categorically adrift…
    praca
    Bye to complete!
    praca kraków

  14. Zero says:

    Hello! Great work! Is it posible to disable gestures beyond the drawzone mask?

  15. [...] Flash Player 10.1 has some but I wanted to find something quick and easy. I found such an API from ByteArray.org. It’s a very easy and nice API, just enough for [...]

     
  16. chenyungui says:

    This days i just try your code, when i am try:
    var a:Array = [2, 6, 0, 1, 2, 3];
    var b:Array = [2, 6, 0, 1, 2, 3];
    trace(costLeven(a, b)); // return 1.

    i think in function costLeven(); the end of code should be:
    return w[a.length][b.length];

  17. [...] Besides this project, I also found some interesting project, which ignites my passion in these work. http://www.bytearray.org/?p=91 [...]

     
  18. Arindam Mojumder says:

    No its not working properly. Many time it is showing wrong alphabet or letter.
    But still it is awesome…

  19. jack says:

    i made a port in Obj-c.
    it’s available here:
    https://github.com/divol/gesture-Carnival
    i changed the levenstein algo, as the one included into the code source do not return a good result using the patterns to recognise as entry. strange

    need to be tuned

    i made a test bet for iphone, il’d add

  20. Tasovi says:

    Does this also work with touch guestures?

  21. tasovi says:

    does this also work with touch?
    or only with the mouse?

  22. Norel says:

    Works perfectly. Thanks !

Leave a Reply

Open Sort Options

Sort comments by:
  • * Applied after refresh

ByteArray.org
Fun with code since 2006.