Sign in to follow this  
Followers 0
orange

Mouse Gestures -- What do you think?

7 posts in this topic

#1 ·  Posted (edited)

Here is a fun thing that I have been working on for a few days now. It is a simple program that runs in the background and every few miliseconds it gets a mouse position. Then, after waiting for some interval, it gets another position and analyzes it as either Up, Down, Right, or Left. There is an inherent error component involved as well to make recognition easier.

So, after the program recognises a movement it calls a basic RUN(.....) function. My settings are for an UP DOWN pattern to open firefox and a side to side for Thunderbird.

Lets see what you all think. Let me know if there is something glaringly ignorant that I am doing, or let me know if you think that I can make this code better (and I know that I can).

The two attached files are two different files for the same program. One is for configuration of the settings, and the other is the program that runs in the background and records mouse movement.

The config file is filed in the windows directory: C:/WINDOWS/USEROPTIONS.DAT

Syntactically speaking, the three numerical settings are first (Error, Distance, Speed), then the filename, then the pattern.

The Pattern needs to be in ALL CAPS. The current four directions are U D R L.

Let me know what you think.

~orange

Edited by orange

Share this post


Link to post
Share on other sites



well... there is already one bug that I foresee causing some issues.

The motion of the mouse is stored in a kind of a cache, so when you move right, then wait a few moments, and move left it will interpret your motion as RIGHT LEFT. This is not all that cool.

I am working on a fix for that problem. I will post the solution tonight or in the morning.

Any others?

Share this post


Link to post
Share on other sites

provide the script please no one will run the .exe only

Share this post


Link to post
Share on other sites

provide the script please no one will run the .exe only

also if it's just the script.. post the code or upload it in this thread.. i'm starting to hate zips..

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

provide the script please no one will run the .exe only

Here is the second Version. Problem Fixed.

Any other suggestions? The scripts are attached and here:

Settings File:

#include <GUIConstants.au3>
#include <file.au3>
#include <Array.au3

If(FileExists("c:\windows\useroptions.dat") = 0) Then _FileCreate ("C:\windows\useroptions.dat")

;----------------------Create GUI-----------------------------

GUICreate("Mouse Gestures",300,300)
$action = String("")

$okbutton = GuiCtrlCreateButton ("Apply",15,260,70,20)
$recordbutton = GuiCtrlCreateButton ("Record",115,260,70,20)
$addgesture = GuiCtrlCreateButton ("Add Gesture",105,230,90,20)
$cancelbutton = GuiCtrlCreateButton ("Exit",215,260,70,20)
$reset = GuiCtrlCreateButton ("Reset",15,230,40,20)

$slider1 = GUICtrlCreateSlider (10,10,275,20)
GUICtrlSetLimit(-1,100,0) 
GuiCtrlSetData(-1, 30)
GUICtrlCreateLabel ( "Acceptable Error", 110, 30)

$slider2 = GUICtrlCreateSlider (10,50,275,20)
GUICtrlSetLimit(-1,100,0) 
GuiCtrlSetData(-1, 50)
GUICtrlCreateLabel ( " Pixels Per Move", 110, 70)

$slider3 = GUICtrlCreateSlider (10,90,275,20)
GUICtrlSetLimit(-1,1000,0) 
GuiCtrlSetData(-1, 100)
GUICtrlCreateLabel ( "Faster                     Acceptable Speed                    Slower", 10, 110)

$instructions = GUICtrlCreateInput ( "", 10,  130, 275, 20)
GUICtrlSetState(-1,$GUI_ACCEPTFILES)
GUICtrlCreateLabel ( " Instruction Set", 110, 155)

$FilePath = GUICtrlCreateInput ( "   Filepath to Open on Successful Gesture Recognition", 10,  170, 275, 20)
GUICtrlSetState(1,$GUI_ACCEPTFILES)
GUICtrlCreateLabel ( " Shortcut Target", 110, 200)

$duration = GUICtrlCreateInput("2000",220,230,40,20)
GUICtrlSetState(-1,$GUI_ACCEPTFILES)
GUICtrlCreateLabel ( "Time", 265, 235)


GuiSetState()

;--------------------Begin Program ------------------------------

While 1
    $msg = GUIGetMsg()
        
        Select
        Case $msg = $GUI_EVENT_CLOSE Or $msg = $cancelbutton
            ExitLoop

        Case $msg = $recordbutton
            record()

        Case $msg = $okbutton
            clickapply()

        Case $msg = $addgesture
            clickadd()

        Case $msg = $reset
            clickres()

        EndSelect

;GUIctrlread($slider1)
WEnd
GUIDelete()
Exit

;-----------------------------Functions--------------------

Func clickres()
    $handle = FileOpen ( "C:\windows\useroptions.dat", 0)
    $var1 = FileReadLine($handle,1)
    $var2 = FileReadLine($handle,2)
    $var3 = FileReadLine($handle,3)
    $var4 = FileReadLine($handle,4)
    FileClose($handle)

    _FileCreate ("C:\windows\useroptions.dat")

    $handle = FileOpen ( "C:\windows\useroptions.dat", 1)
    FileWriteLine($handle, $var1)
    FileWriteLine($handle, $var2)
    FileWriteLine($handle, $var3)
    FileWriteLine($handle, $var4)
    FileClose($handle)
    MsgBox(4096,"Reset","Gestures Deleted")
EndFunc

Func clickadd()
$handle = FileOpen ( "C:\windows\useroptions.dat", 1)
    FileWriteLine($handle,GUIctrlread($FilePath))
    FileWriteLine($handle,GUIctrlread($instructions))
    FileClose ($handle)
    MsgBox(4096,"Gesture Added","Gesture Successfully Added. There are " & int((_FileCountLines("c:\windows\useroptions.dat")-3)/2) & " Instructions Programmed.")
        
EndFunc

Func clickapply()

    Dim $instruct[1]
    $instruct[0] = String("-")
    $count = _FileCountLines("C:\windows\useroptions.dat" )
    $handle = FileOpen ( "C:\windows\useroptions.dat", 0)

    For $i = 5 to $count Step 1
       _ArrayAdd($instruct,FileReadLine($handle,$i))
    Next

    FileClose ($handle)

    $handle = FileOpen ( "C:\windows\useroptions.dat", 2)
    FileWriteLine($handle,GUIctrlread($slider1))
    FileWriteLine($handle,GUIctrlread($slider2))
    FileWriteLine($handle,GUIctrlread($slider3))
    FileWriteLine($handle,GUIctrlread($duration))

    For $i = 1 to $count-4 Step 1
       FileWriteLine($handle,$instruct[$i])
    Next

    FileClose ($handle)
endFunc

Func record()
$inst = String("")
$temp = String("")
MsgBox(4096,"Record Mouse Movement...","Click to begin recording. Hit Space Bar to Exit Record Mode")
WinSetTrans("Mouse Gestures","",100)
Send("{CAPSLOCK}")
Send("{TAB}")
Send("{TAB}")
Send("{TAB}")
Send("{TAB}")
while 1
    Direction($inst)
    $temp = GUIctrlread($instructions)
    If(StringRight($temp,1) = " ") Then ExitLoop
Wend
Send("{CAPSLOCK}")
Send("{BACKSPACE}")
WinSetTrans("Mouse Gestures","",255)
endFunc


Func Direction($temp)
 $error = GUIctrlread($slider1)
 $distance = GUIctrlread($slider2)
 $loc = MouseGetPos()
 $loc1 = $loc
 Sleep(100)
 $loc = MouseGetPos()

If (Abs($loc[0]-$loc1[0])<$error AND Abs($loc[1]-$loc1[1])>$distance) Then
 If ($loc[1] < $loc1[1]) Then Send("U")
 If ($loc[1] > $loc1[1]) Then Send("D")
 EndIf

If (Abs($loc[1]-$loc1[1])<$error AND Abs($loc[0]-$loc1[0])>$distance) Then
 If ($loc[0] < $loc1[0]) Then Send("L")
 If ($loc[0] > $loc1[0]) Then Send("R")
EndIf

endFunc

And here is the code of the file that runs in the background to check gestures:

#include <GUIConstants.au3>
#include <Array.au3>
#include <file.au3>

Dim $instruct[1]
$instruct[0] = String("-")

;-------------------OPEN DAT FILE-------------------
$handle = FileOpen ( "C:\windows\useroptions.dat", 0)
$error = int(FileReadLine($handle,1))
$distance = int(FileReadLine($handle,2))
$count = _FileCountLines("C:\windows\useroptions.dat" )
$speed = int(FileReadLine($handle,3))
$duration = int(FileReadLine($handle,4))

For $i = 5 to $count Step 1
   _ArrayAdd($instruct,FileReadLine($handle,$i))
  ;_ArrayDisplay ( $instruct, "")
Next

FileClose($handle)

$action = String("")

;---------------------MAIN--------------------------    

$timer = TimerInit ( )
While 1
If (Timerdiff($timer)>$duration) Then 
    $timer = TimerInit ( )
    $action = String("")
EndIf
Direction($action)
If(StringLen($action)=2) Then Test()
WEnd

Exit

;------------------FUNCTIONS------------------------


Func Test()
 For $i = 2 to $count-4 Step 2
  $test = $instruct[$i]
  
  If (StringLeft($test,StringLen($action)) = StringLeft($action, StringLen($action))) Then
   If (StringLen($action) = StringLen($test)) Then
    run($instruct[$i-1])
    $action = String("")
    ExitLoop
   EndIf
  Else
 ;$action = String("")
  EndIf
 Next
 $action = String("")
EndFunc


Func Direction($temp)
 $loc = MouseGetPos()
 $loc1 = $loc
 Sleep($speed)
 $loc = MouseGetPos()

If (Abs($loc[0]-$loc1[0])<$error AND Abs($loc[1]-$loc1[1])>$distance) Then
 If ($loc[1] < $loc1[1]) Then $action = $temp & "U"
 If ($loc[1] > $loc1[1]) Then $action = $temp & "D"
EndIf

If (Abs($loc[1]-$loc1[1])<$error AND Abs($loc[0]-$loc1[0])>$distance) Then
 If ($loc[0] < $loc1[0]) Then $action = $temp & "L"
 If ($loc[0] > $loc1[0]) Then $action = $temp & "R"
EndIf

endFunc

Edited by orange

Share this post


Link to post
Share on other sites

If you want to continue on this one, you could look here for some ideas.

This is something I've been using for some 1.5 years now, it basically does the same as your script, so have a look for inspiration.

Regards


Don't take my pic to serious...~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~You Looked, but you did not see!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Share this post


Link to post
Share on other sites

I suppose its a good idea. It works but i wont use it. I prefer my quick launch and start menu. You might want to add a browse button to the file path.


My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.

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