auto 发表于 2011-11-11 19:38:06

AU3如何实现手势?想用手势实现几个简单的功能

本帖最后由 auto 于 2011-11-11 19:57 编辑

AU3如何实现手势?想用手势实现几个简单的功能
不知道难度有多大,要换maxthon等浏览器一样,能够画出线,能识别上下左右画线就OK啦

gzh888666 发表于 2011-11-11 19:49:00

帮你顶一下,期待高人出现

虫子樱桃 发表于 2011-11-11 20:41:28

本帖最后由 虫子樱桃 于 2011-11-11 20:44 编辑

回复 1# auto


    谷歌关键字“Mouse Gestures autoit”
http://www.google.com.hk/search?hl=zh-CN&newwindow=1&safe=strict&client=firefox-a&hs=15B&rls=org.mozilla%3Azh-CN%3Aofficial&q=Mouse+Gestures+autoit&oq=Mouse+Gestures+autoit&aq=f&aqi=g10&aql=&gs_sm=e&gs_upl=1629l4269l0l4481l2l2l0l0l0l0l347l347l3-1l1l0

洋人的一个例子#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 ®", $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 < $pos_m - 20
                ToolTip ("L", 0, 0)
                Global $set = "1"
            Case $pos_n > $pos_m + 20
                ToolTip ("R", 0, 0)
                Global $set = "2"
            Case $pos_n < $pos_m
                ToolTip ("U", 0, 0)
                Global $set = "3"
            Case $pos_n > $pos_m
                ToolTip ("D", 0, 0)
                Global $set = "4"
      EndSelect
      Sleep (100)
    WEnd

    If $pos_n < $pos_m - 20 Then
      DoGesture()
    ElseIf $pos_n > $pos_m + 20 Then
      DoGesture()
    EndIf
    If $pos_n < $pos_m Then
      DoGesture()
    ElseIf $pos_n > $pos_m 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

auto 发表于 2011-11-11 20:51:42

这个有试过.看不懂..而且不能画线.

happytc 发表于 2011-11-11 21:09:51

回复 1# auto

想做到好用,可是个大工程了
你可以用StrokeIt的SDK来开发,那样容易多了:http://www.tcbmi.com/strokeit/
主要是轨迹识别比较麻烦


给你个最简的Demo,希望抛砖引玉了。写出好用的代码,别忘了在这里秀一下

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

$hGui = GUICreate("鼠标手势Demo", 300, 250)

$ErrorLevelSlider = GUICtrlCreateSlider(10, 10, 270, 20)
GUICtrlSetLimit(-1, 100, 0)
GUICtrlSetData(-1, 30)
GUICtrlCreateLabel("可接受的错误水平", 110, 40)

$DistSlider = GUICtrlCreateSlider(10, 90, 270, 20)
GUICtrlSetLimit(-1, 100, 0)
GUICtrlSetData(-1, 50)
GUICtrlCreateLabel("每次移动的像素数", 110, 120)

$InstructInput = GUICtrlCreateInput("", 10, 150, 270, 20)

$StartButton = GUICtrlCreateButton("开始", 100, 200, 80, 20)
GUISetState(@SW_SHOW, $hGui)


While True
        $msg = GUIGetMsg()
        Switch $msg
                Case $GUI_EVENT_CLOSE
                        ExitLoop
                Case $Startbutton
                        Start()
        EndSwitch
WEnd
GUIDelete()
Exit



Func Start()
        $inst = String("")
        $temp = String("")
        GUICtrlSetState($InstructInput, $GUI_FOCUS)
        WinSetTrans($hGui, "", 100)
        Send("{CAPSLOCK}")
        Send("{TAB}")
        Send("{TAB}")
        Send("{TAB}")
        Send("{TAB}")
        While True
                Direction($inst)
                $temp = GUICtrlRead($InstructInput)
                If _IsPressed("1B") Then ExitLoop
        WEnd
EndFunc


Func Direction($temp)
        $ErrorLevel = GUICtrlRead($ErrorLevelSlider)
        $Distance = GUICtrlRead($DistSlider)
        $MousePosOri = MouseGetPos()
        Sleep(100)
        $MousePos = MouseGetPos()

        If (Abs($MousePos - $MousePosOri) < $ErrorLevel And Abs($MousePos - $MousePosOri) > $Distance) Then
                If ($MousePos < $MousePosOri) Then Send("U")
                If ($MousePos > $MousePosOri) Then Send("D")
        EndIf

        If (Abs($MousePos - $MousePosOri) < $ErrorLevel And Abs($MousePos - $MousePosOri) > $Distance) Then
                If ($MousePos < $MousePosOri) Then Send("L")
                If ($MousePos > $MousePosOri) Then Send("R")
        EndIf
EndFunc

afan 发表于 2011-11-11 22:54:45

去年写过一个,当时没想到有多大用,现在想找又找不到了……

auto 发表于 2011-11-12 17:57:31

回复 6# afan


能否再找找看..

auto 发表于 2011-11-12 17:58:37

回复auto

想做到好用,可是个大工程了
你可以用StrokeIt的SDK来开发,那样容易多了:
主要是轨迹识 ...
happytc 发表于 2011-11-11 21:09 http://www.autoitx.com/images/common/back.gif


   用第三方SDK来编写,对我来说,难度太大了.不会玩

asdasdasd 发表于 2011-11-12 23:10:23

是否可以这样,划线是不难解决,至于判断,可以通过起点和终点的XY坐标进行粗略判断?

netegg 发表于 2011-11-13 02:00:50

回复 9# asdasdasd
划线不难?可否凭空画条线出来?试试看,但要记住是在对方句柄上不是自己建的窗口

happytc 发表于 2011-11-13 04:35:29

回复asdasdasd
划线不难?可否凭空画条线出来?试试看,但要记住是在对方句柄上不是自己建的窗口
netegg 发表于 2011-11-13 02:00 http://www.autoitx.com/images/common/back.gif

的确很容易的,先给你个简单的GDI32的例子,当然用GDI+有平滑线画出起来更好看点,道理是一样的,我就给一个了


#include <Misc.au3>

HotKeySet("{Esc}", "_exit")

While True
        If _IsPressed("01") Then
                $aPosA = MouseGetPos()
                Do
                        $aPosB = MouseGetPos()
                        DrawLine()
                        Sleep(25)
                Until Not _IsPressed("01")
        EndIf
        Sleep(50)
WEnd


Func DrawLine()
        $hWnd = DllCall("user32.dll", "int", "GetDC", "hwnd", 0)
        $hPen = DllCall("gdi32.dll", "int", "CreatePen", "int", 0, "int", 2, "int", 0x99DF88)
        DllCall("gdi32.dll", "int", "SelectObject", "int", $hWnd, "int", $hPen)
        DllCall("GDI32.dll", "int", "MoveToEx", "hwnd", $hWnd, "int", $aPosA, "int", $aPosA, "int", 0)
        DllCall("GDI32.dll", "int", "LineTo", "hwnd", $hWnd, "int", $aPosB, "int", $aPosB)
        DllCall("user32.dll", "int", "ReleaseDC", "hwnd", 0, "int", $hWnd)
EndFunc


Func _exit()
        Exit
EndFunc

netegg 发表于 2011-11-13 07:35:37

回复 11# happytc

这个我知道,楼主的那个意思貌似是要在某个界面上划线,而且还要交互

auto 发表于 2011-11-13 10:55:13

回复 11# happytc


    这个能画线,不过只能在桌面上画,我需要任意窗口(或者太难)只在IE窗口画可以.
貌似在桌面上画,还有方框

auto 发表于 2011-11-13 10:57:02

回复 12# netegg


    如果支持不了任意窗口,就支持IE窗口也行吧
只要简单实现几个[向左,向右,向上,向下]画线的识别就可以了

afan 发表于 2011-11-13 12:26:33

我当时写的思路还记得,现在没时间写
1,拦截鼠标右键
2,创建个透明窗口,注意样式及扩展样式以及显示方式。
3,在鼠标按下的时间内循环,根据鼠标位置DrawLine绘制连续的线条。
4,根据鼠标位置转折点的坐标判断鼠标轨迹。
5,鼠标弹起后删除窗口及执行轨迹动作。
页: [1] 2
查看完整版本: AU3如何实现手势?想用手势实现几个简单的功能