Sign in to follow this  
Followers 0
erifash

Simple Mouse Gestures

7 posts in this topic

I have created a fairly simple mouse gesture script. The gesture is a string of digits representing directions the mouse needs to move in. The directions are numpad-based and the eight keys surrounding the 5 are allowed. The directions are stored in a cache that will be cleared if the mouse is inactive for more than half of a second. Thanks to blindwig for the GetAnglePO function! Here is the code:

$gesture = "896321478"
$sleep = 100
$debug = True

#cs
      DIRECTIONS:
      numpad-sytle

   7    8    9

   4    +    6

   1    2    3

#ce

Global Const $pi = 3.14159265358979
$current = ""
$direction = ""
$timer = TimerInit()

While 1
   $pos_old = MouseGetPos()
   Sleep($sleep)
   $pos_new = MouseGetPos()
   If $pos_new[0] = $pos_old[0] and $pos_new[1] = $pos_old[1] Then ContinueLoop
   If TimerDiff($timer) > 500 Then $current = ""
   $a = GetAnglePO($pos_new[0] - $pos_old[0], $pos_new[1] - $pos_old[1]) * 57.2957795130823
   Select
      Case $a >= 337.5 or $a < 22.5
         $direction = "6"
      Case $a >= 22.5 and $a < 67.5
         $direction = "3"
      Case $a >= 67.5 and $a < 112.5
         $direction = "2"
      Case $a >= 112.5 and $a < 157.5
         $direction = "1"
      Case $a >= 157.5 and $a < 202.5
         $direction = "4"
      Case $a >= 202.5 and $a < 247.5
         $direction = "7"
      Case $a >= 247.5 and $a < 292.5
         $direction = "8"
      Case $a >= 292.5 and $a < 337.5
         $direction = "9"
   EndSelect
   If $direction <> StringRight($current, 1) Then $current &= $direction
   If $debug Then ToolTip("Current:" & @TAB & $current & @CRLF & "Direction:" & @TAB & $direction)
   If StringInStr($current, $gesture) Then
      MsgBox(0, "gesture", $current)
      $current = ""
   EndIf
   $timer = TimerInit()
WEnd

Func GetAnglePO( $x, $y )   ;by blindwig
   Select
      Case $x > 0
         If $y >= 0 Then
            Return ATan($y / $x)
         Else
            Return ATan($y / $x) + 2 * $pi
         EndIf
      Case $x = 0
         If $y = 0 Then
            Return 0
         ElseIf $y > 0 Then
            Return $pi / 2
         Else
            Return 3 * $pi / 2
         EndIf
      Case $x < 0
         Return ATan($y / $x) + $pi
   EndSelect
EndFunc

The included gesture is a simple clockwise circle. By default debug mode is turned on. You might need to modify the sleep depending on the speed you go at. You can modify the settings by changing the variables at the top. I hope you like it! :P

Share this post


Link to post
Share on other sites



Nice script, I have been using a plugin for firefox alot like this for a long time, I know I will be using this now, thanks.


[quote name='DaleHohm']You have a strange habit of posting error messages that don't match your code.[/quote][quote name='SmOke_N']Forget the learning... straight to the scripting :lol: (laugh.gif)[/quote]

Share this post


Link to post
Share on other sites

If you have one of those tablet laptops it would be even cooler. Just draw a circle on the screen to run a program or whatever! :P

Share this post


Link to post
Share on other sites

Very cool. Very nice!

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

This reminds me of "Stroke-it" (ignore the name :P )

Nice script!

Edited by Paulie

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

How can I add to my script Simple Mouse Gestures when I want that gestures works only in one specifed window and works when right mouse button is droped down - like in broeser Opera or Firefeox with extension. Gestures will send keystrokes to this window/program.

Edited by SebaM

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

I have added some to this code.

In this version the gesture is only processed while the right mouse button is down. (like firefox and opera)

I think i may try to make it recognize what program has focus so you can assign different gestures for different programs.

And maybe I'll try to make a setup GUI to assign actions to gestures for different programs.

Gesture Left sends the back command(Alt+Left Arrow)

Gesture Right sends the forward command(Alt+Right Arrow)

Gesture Up sends the refresh command(F5)

Gesture Down sends the stop command(esc)

Gesture Down-Left Sends the Close Command(Alt+F4)

#Include <Misc.au3>

#cs
    DIRECTIONS:
    numpad-sytle
    
    7   8   9
    
    4   +   6
    
    1   2   3
    
#ce

$gesture1 = "24"
$gesture2 = "4"
$gesture3 = "6"
$gesture4 = "8"
$gesture5 = "2"
$gesturefound = 0
$sleep = 100
$debug = False
$current = ""
$direction = ""
$timer = TimerInit()
Global Const $pi = 3.14159265358979

Check()

Func Check();Check for Gestures
    While 1
        While _IsPressed(02)
            $pos_old = MouseGetPos()
            Sleep($sleep)
            $pos_new = MouseGetPos()
            If $pos_new[0] = $pos_old[0] and $pos_new[1] = $pos_old[1] Then ContinueLoop
            If TimerDiff($timer) > 500 Then $current = ""
            $a = GetAnglePO($pos_new[0] - $pos_old[0], $pos_new[1] - $pos_old[1]) * 57.2957795130823
            Select
                Case $a >= 337.5 or $a < 22.5
                    $direction = "6"
                Case $a >= 22.5 and $a < 67.5
                    $direction = "3"
                Case $a >= 67.5 and $a < 112.5
                    $direction = "2"
                Case $a >= 112.5 and $a < 157.5
                    $direction = "1"
                Case $a >= 157.5 and $a < 202.5
                    $direction = "4"
                Case $a >= 202.5 and $a < 247.5
                    $direction = "7"
                Case $a >= 247.5 and $a < 292.5
                    $direction = "8"
                Case $a >= 292.5 and $a < 337.5
                    $direction = "9"
            EndSelect
            If $direction <> StringRight($current, 1) Then $current &= $direction
            If $debug Then ToolTip("Current:" & @TAB & $current & @CRLF & "Direction:" & @TAB & $direction)
            $timer = TimerInit()
            Select
                Case $current=$gesture1
                    $gesturefound = 1
                Case $current=$gesture2
                    $gesturefound = 2
                Case $current=$gesture3
                    $gesturefound = 3
                Case $current=$gesture4
                    $gesturefound = 4
                Case $current=$gesture5
                    $gesturefound = 5
            EndSelect
        WEnd
        Action()
    WEnd
EndFunc

Func Action();Take Action
    If $gesturefound > 0 Then
        Sleep($sleep)
        Send("{ESC}")
        Sleep($sleep)
        Select
            Case $gesturefound = 1
                Send("!{F4}")
            Case $gesturefound = 2
                Send("!{LEFT}")
            Case $gesturefound = 3
                Send("!{Right}")
            Case $gesturefound = 4
                Send("{F5}")
            Case $gesturefound = 5
                Send("{ESC}")
        EndSelect
        $current = ""
        $gesturefound = 0
    EndIf
    sleep($sleep)
EndFunc

Func GetAnglePO( $x, $y ) ;by blindwig
    Select
        Case $x > 0
            If $y >= 0 Then
                Return ATan($y / $x)
            Else
                Return ATan($y / $x) + 2 * $pi
            EndIf
        Case $x = 0
            If $y = 0 Then
                Return 0
            ElseIf $y > 0 Then
                Return $pi / 2
            Else
                Return 3 * $pi / 2
            EndIf
        Case $x < 0
            Return ATan($y / $x) + $pi
    EndSelect
EndFunc
Edited by random667

It is really sad to see a family torn apart by something as simple as a pack of wolves.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0