Jump to content

Mouse Gesture


phantom
 Share

Recommended Posts

Hello, inspired by the firefox plugin i decide to have a chop at making something similar but making it open what i choose.

Hold down middle mouse button and move your mouse either left, right, up or down to perform the set gesture. I have seen something similar to this on the forum. www.autoitscript.com/forum/index.php?showtopic=32059&hl=Mouse+Gesture

Set gesture 1-4 through the tray menu, Heres the code:

#include <Misc.au3>
#include <GUIConstants.au3>

Opt ("TrayAutoPause", 0);1 = pause
Opt ("WinTitleMatchMode", 3);1 = default, 2 = substring, 3 = exact

Dim $GUI, $OpenDefaultBrowser, $OpenMyComputer, $UD_open1, $UD_open2

$menu = TrayCreateMenu ("Set Gesture")
$L = TrayCreateItem ("Set Gesture 1 (L)", $menu)
$R = TrayCreateItem ("Set Gesture 2 (R)", $menu)
$U = TrayCreateItem ("Set Gesture 3 (U)", $menu)
$D = TrayCreateItem ("Set Gesture 4 (D)", $menu)
TraySetState ()

While 1
    Sleep (50)
    $msg = TrayGetMsg ()
    Select
        Case _IsPressed ("04")
            GetGesture()
        Case $msg = $L
            Global $set = "1"
            If Not WinExists ("Gestures Setup") Then
                SetUp()
            Else
                WinSetState ("Gestures Setup", "", @SW_SHOW)
                SetUp()
            EndIf
        Case $msg = $R
            Global $set = "2"
            If Not WinExists ("Gestures Setup") Then
                SetUp()
            Else
                WinSetState ("Gestures Setup", "", @SW_SHOW)
                SetUp()
            EndIf
        Case $msg = $U
            Global $set = "3"
            If Not WinExists ("Gestures Setup") Then
                SetUp()
            Else
                WinSetState ("Gestures Setup", "", @SW_SHOW)
                SetUp()
            EndIf
        Case $msg = $D
            Global $set = "4"
            If Not WinExists ("Gestures Setup") Then
                SetUp()
            Else
                WinSetState ("Gestures Setup", "", @SW_SHOW)
                SetUp()
            EndIf
    EndSelect
WEnd

Func GetGesture()
    Local $pos_m = MouseGetPos ()
    While _IsPressed ("04")
        $pos_n = MouseGetPos ()
        Select
            Case $pos_n[0] < $pos_m[0] - 20
                ToolTip ("L", 0, 0)
                Global $set = "1"
            Case $pos_n[0] > $pos_m[0] + 20
                ToolTip ("R", 0, 0)
                Global $set = "2"
            Case $pos_n[1] < $pos_m[1]
                ToolTip ("U", 0, 0)
                Global $set = "3"
            Case $pos_n[1] > $pos_m[1]
                ToolTip ("D", 0, 0)
                Global $set = "4"
        EndSelect
        Sleep (100)
    WEnd

    If $pos_n[0] < $pos_m[0] - 20 Then
        DoGesture()
    ElseIf $pos_n[0] > $pos_m[0] + 20 Then
        DoGesture()
    EndIf
    If $pos_n[1] < $pos_m[1] Then
        DoGesture()
    ElseIf $pos_n[1] > $pos_m[1] Then
        DoGesture()
    EndIf
EndFunc   ;==>GetGesture

Func SetUp()
    If WinExists ("Gestures Setup") Then
        If FileExists (@ScriptDir & "/Gestures Setup.ini") Then
            $check1 = IniRead (@ScriptDir & "/Gestures Setup.ini", "Gesture" & $set, "Open Default Browser", "none")
            $check2 = IniRead (@ScriptDir & "/Gestures Setup.ini", "Gesture" & $set, "Open My Computer", "none")
            GUICtrlSetState ($OpenDefaultBrowser, $check1)
            GUICtrlSetState ($OpenMyComputer, $check2)
        EndIf
    Else
        Global $GUI = GUICreate ("Gestures Setup", 177, 133)
        Global $Set2 = GUICtrlCreateButton ("Set", 8, 105, 161, 25)
        $DefaultFunctions = GUICtrlCreateTab (8, 8, 161, 95)
        GUICtrlCreateTabItem ("Gestures")
        Global $OpenDefaultBrowser = GUICtrlCreateCheckbox ("Open Default Browser", 16, 42, 137, 17)
        Global $OpenMyComputer = GUICtrlCreateCheckbox ("Open My Computer", 16, 66, 137, 17)
        GUICtrlCreateTabItem ("UD Gestures")
        Global $UD_Openg = GUICtrlCreateCheckbox ("Open file", 16, 42, 137, 17)
        Global $UD_Openg2 = GUICtrlCreateCheckbox ("Open file", 16, 66, 137, 17)
        If FileExists (@ScriptDir & "/Gestures Setup.ini") Then
            $check1 = IniRead (@ScriptDir & "/Gestures Setup.ini", "Gesture" & $set, "Open Default Browser", "none")
            $check2 = IniRead (@ScriptDir & "/Gestures Setup.ini", "Gesture" & $set, "Open My Computer", "none")
            GUICtrlSetState ($OpenDefaultBrowser, $check1)
            GUICtrlSetState ($OpenMyComputer, $check2)
        EndIf
        GUISetState ()
    EndIf

    While 1
        $msg = GUIGetMsg ()
        Switch $msg
            Case $Set2
                If GUICtrlRead ($OpenDefaultBrowser) = $GUI_CHECKED Then
                    IniWrite (@ScriptDir & "/Gestures Setup.ini", "Gesture" & $set, "Open Default Browser", "1")
                Else
                    IniWrite (@ScriptDir & "/Gestures Setup.ini", "Gesture" & $set, "Open Default Browser", "4")
                EndIf
                If GUICtrlRead ($OpenMyComputer) = $GUI_CHECKED Then
                    IniWrite (@ScriptDir & "/Gestures Setup.ini", "Gesture" & $set, "Open My Computer", "1")
                Else
                    IniWrite (@ScriptDir & "/Gestures Setup.ini", "Gesture" & $set, "Open My Computer", "4")
                EndIf
                If GUICtrlRead ($UD_Openg) = $GUI_CHECKED Then
                    IniWrite (@ScriptDir & "/Gestures Setup.ini", "Gesture" & $set, "Open File: " & $UD_open1, "1")
                Else
                    IniWrite (@ScriptDir & "/Gestures Setup.ini", "Gesture" & $set, "Open File: " & $UD_open1, "4")
                EndIf
                If GUICtrlRead ($UD_Openg2) = $GUI_CHECKED Then
                    IniWrite (@ScriptDir & "/Gestures Setup.ini", "Gesture" & $set, "Open File: " & $UD_open2, "1")
                Else
                    IniWrite (@ScriptDir & "/Gestures Setup.ini", "Gesture" & $set, "Open File: " & $UD_open2, "4")
                EndIf
                MsgBox (0, "Set", "Options set.")
            Case $UD_Openg
                If GUICtrlRead ($UD_Openg) = $GUI_CHECKED Then
                    Global $UD_open1 = FileOpenDialog ("Select file to open when gesture " & $set & " is done:", @HomeDrive, "All (*.*)")
                Else
                    Sleep (10)
                EndIf
            Case $UD_Openg2
                If GUICtrlRead ($UD_Openg2) = $GUI_CHECKED Then
                    Global $UD_open2 = FileOpenDialog ("Select file to open when gesture " & $set & " is done:", @HomeDrive, "All (*.*)")
                Else
                    Sleep (10)
                EndIf
            Case $GUI_EVENT_CLOSE
                WinSetState ("Gestures Setup", "", @SW_HIDE)
                Global $set = ""
                ExitLoop
        EndSwitch
        Sleep (30)
    WEnd
EndFunc   ;==>SetUp

Func DoGesture()
    If FileExists (@ScriptDir & "/Gestures Setup.ini") Then
        Local $check1 = IniRead (@ScriptDir & "/Gestures Setup.ini", "Gesture" & $set, "Open Default Browser", "none")
        Local $check2 = IniRead (@ScriptDir & "/Gestures Setup.ini", "Gesture" & $set, "Open My Computer", "none")
        Local $check3 = IniRead (@ScriptDir & "/Gestures Setup.ini", "Gesture" & $set, "Open File: " & $UD_open1, "none")
        Local $check4 = IniRead (@ScriptDir & "/Gestures Setup.ini", "Gesture" & $set, "Open File: " & $UD_open2, "none")
    EndIf
    If $check1 = 1 Then
        ShellExecute ("www.google.com")
    ElseIf $check2 = 1 Then
        Run ("Explorer.exe /root, ,::{20D04FE0-3AEA-1069-A2D8-08002B30309D}")
    EndIf
    If $check3 = 1 Then
        ShellExecute ($UD_open1)
    ElseIf $check4 = 1 Then
        ShellExecute ($UD_open2)
    EndIf
    ToolTip ("")
EndFunc   ;==>DoGesture

After looking at the code you can probably tell I still have much to learn. :) all comments welcome :)

Link to comment
Share on other sites

if you set the gesture to 1 or "L" (Left) then hold the middle mouse button in and move it left then release and it should do what your have ticked. You should see a tooltip in the top left of your screen telling you which way your mouse is from the start position L,R,U or D.

Link to comment
Share on other sites

  • 6 years later...

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...