Jump to content

KeyboardControlMoveObject


newsak2005
 Share

Recommended Posts

KeyboardControlMoveObject

Discript:Use Arrow keys Left-Right-Up-Down Move Object go to very way.

#NoTrayIcon
#cs==============Info================
Createdate:11/August/2011
Name:KeyboardControlMoveObject
Discript:Use Arrow keys move object
Designby:sak2005
#ce==================================
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Include <Misc.au3>

Opt("MustDeclareVars", 1)
Global $guititle = 'KeyboardControlMoveObject'
Global $iPosX = 300, $iPosY = 250, $cID = 'Static1'

main()
Func main()
    GUICreate($guititle, 600, 500, -1, -1)
    GUICtrlCreateIcon(@SystemDir&"\shell32.dll", -47, $iPosX, $iPosY, 32, 32, BitOR($SS_NOTIFY,$WS_GROUP))
    GUISetState(@SW_SHOW)

    AdlibRegister("_timer", 1)
    Do
    Until GUIGetMsg()=$GUI_EVENT_CLOSE
EndFunc

Func _timer()
    Local $iPos = ControlGetPos($guititle, "", $cID)
    Local $dll = DllOpen("user32.dll")
    Select
        Case _IsPressed("25", $dll)
            $iPosX -=1
            ControlMove($guititle, "", $cID, $iPosX, $iPos[1], 32, 32)
            If $iPosX = -30 Then $iPosX = 600
        Case _IsPressed("26", $dll)
            $iPosY -=1
            ControlMove($guititle, "", $cID, $iPos[0], $iPosY, 32, 32)
            If $iPosY = -30 Then $iPosY = 500
        Case _IsPressed("27", $dll)
            $iPosX +=1
            ControlMove($guititle, "", $cID, $iPosX, $iPos[1], 32, 32)
            If $iPosX = 600 Then $iPosX = -30
        Case _IsPressed("28", $dll)
            $iPosY +=1
            ControlMove($guititle, "", $cID, $iPos[0], $iPosY, 32, 32)
            If $iPosY = 500 Then $iPosY = -30
    EndSelect
        DllClose($dll)
EndFunc

===========================================================

Use Library DLL

#NoTrayIcon
#cs============Info=================
Createdate:11/August/2011
Name:KeyboardControlMoveObject.
FuncLib:AutoItX3.dll, User32.dll
Discript:Use Arrow keys move object
Designby:sak2005
#ce=================================
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Opt("MustDeclareVars", 1)
Global $dll, $guititle = 'KeyboardControlMoveObject'
Global $iPos, $iPosX = 300, $iPosY = 250, $cID = 'Static1'
Global $Left=25, $Right=26, $Up=27, $Down=28

main()
Func main()
    GUICreate($guititle, 600, 500, -1, -1)
    GUICtrlCreateIcon(@SystemDir&"\shell32.dll", -47, $iPosX, $iPosY, 32, 32, BitOR($SS_NOTIFY,$WS_GROUP))
    GUISetState(@SW_SHOW)
    AdlibRegister("_timer", 1)
    Do
        $iPos = ControlGetPos($guititle, "", $cID)
    Until GUIGetMsg()=$GUI_EVENT_CLOSE
EndFunc

Func _timer()
        $dll = DllOpen("user32.dll")
    Select
        Case KeyIsPressed($Left, $dll)
            $iPosX -=1
            DllCall("AutoItX3.dll", "int", "AU3_ControlMove", _
                                    "str", $guititle, _
                                    "str", "", _
                                    "str", $cID, _
                                    "long", $iPosX, _
                                    "long", $iPos[1], _
                                    "long", 32, _
                                    "long", 32)
            If $iPosX = -30 Then $iPosX = 600
        Case KeyIsPressed($Right, $dll)
            $iPosY -=1
            DllCall("AutoItX3.dll", "int", "AU3_ControlMove", _
                                    "str", $guititle, _
                                    "str", "", _
                                    "str", $cID, _
                                    "long", $iPos[0], _
                                    "long", $iPosY, _
                                    "long", 32, _
                                    "long", 32)
            If $iPosY = -30 Then $iPosY = 500
        Case KeyIsPressed($Up, $dll)
            $iPosX +=1
            DllCall("AutoItX3.dll", "int", "AU3_ControlMove", _
                                    "str", $guititle, _
                                    "str", "", _
                                    "str", $cID, _
                                    "long", $iPosX, _
                                    "long", $iPos[1], _
                                    "long", 32, _
                                    "long", 32)
            If $iPosX = 600 Then $iPosX = -30
        Case KeyIsPressed($Down, $dll)
            $iPosY +=1
            DllCall("AutoItX3.dll", "int", "AU3_ControlMove", _
                                    "str", $guititle, _
                                    "str", "", _
                                    "str", $cID, _
                                    "long", $iPos[0], _
                                    "long", $iPosY, _
                                    "long", 32, _
                                    "long", 32)
            If $iPosY = 500 Then $iPosY = -30
    EndSelect
        DllClose($dll)
EndFunc

Func KeyIsPressed($sHexKey, $vDLL = 'user32.dll') ;see include Misc.au3
    Local $a_R = DllCall($vDLL, "short", "GetAsyncKeyState", "int", '0x' & $sHexKey)
    If @error Then Return SetError(@error, @extended, False)
    Return BitAND($a_R[0], 0x8000) <> 0
EndFunc ;==>End KeyboardControlMoveObject.
Edited by newsak2005
Link to comment
Share on other sites

FullScript. No Include. DLL All.

#NoTrayIcon
#cs============Info=================
Createdate:11/August/2011
Name:KeyboardControlMoveObject.
Syntax:FullScript. No include.
FuncLib:AutoItX3.dll, User32.dll
Discript:Use Arrow keys move object.
Designby:sak2005
#ce=================================
Opt("MustDeclareVars", 1)
Global $hWnd, $hLabel, $iPos, $GuiTitle='KeyboardControlMoveObject'
Global $dll, $iPosX=300, $iPosY=470, $Left=25, $Right=26, $Up=27, $Down=28
Global $CtrlId1='Static1', $CtrlId2='Static2', $GUICTRL_BKCOLOR_TRANSPARENT=2-4

main()
Func main()
    $hWnd = GUICreate($GuiTitle, 600, 500, -1, -1)
    $hLabel = GUICtrlCreateLabel("Speed", 270, 244, 50, 50)
    GUICtrlSetBkColor(-1, $GUICTRL_BKCOLOR_TRANSPARENT)
    GUICtrlCreateIcon(@SystemDir&"\shell32.dll", _
    -47, $iPosX, $iPosY, 32, 32, BitOR(0x0100,0x00020000))
    AdlibRegister("_timer", 1)
    Do
        DllCall("user32.dll", "bool", "ShowWindow", "hwnd", $hWnd, "int", 5)
        $iPos = ControlGetPos($GuiTitle, "", $CtrlId2)
        GUICtrlSetData($hLabel, "Position"&@CRLF&'X='&$iPos[0]&@CRLF&'Y='&$iPos[1])
        Sleep(10)
    Until GUIGetMsg()=-3
EndFunc

Func _timer()
    $dll = DllOpen("user32.dll")
    Select
        Case KeyIsPressed($Left, $dll)
            $iPosX -=2
            DllCall("AutoItX3.dll", "int", "AU3_ControlMove", _
                                    "str", $GuiTitle, _
                                    "str", "", _
                                    "str", $CtrlId2, _
                                    "long", $iPosX, _
                                    "long", $iPos[1], _
                                    "long", 32, _
                                    "long", 32)
            If $iPosX = -30 Then $iPosX = 600
        Case KeyIsPressed($Right, $dll)
            $iPosY -=2
            DllCall("AutoItX3.dll", "int", "AU3_ControlMove", _
                                    "str", $GuiTitle, _
                                    "str", "", _
                                    "str", $CtrlId2, _
                                    "long", $iPos[0], _
                                    "long", $iPosY, _
                                    "long", 32, _
                                    "long", 32)
            If $iPosY = -30 Then $iPosY = 500
        Case KeyIsPressed($Up, $dll)
            $iPosX +=2
            DllCall("AutoItX3.dll", "int", "AU3_ControlMove", _
                                    "str", $GuiTitle, _
                                    "str", "", _
                                    "str", $CtrlId2, _
                                    "long", $iPosX, _
                                    "long", $iPos[1], _
                                    "long", 32, _
                                    "long", 32)
            If $iPosX = 600 Then $iPosX = -30
        Case KeyIsPressed($Down, $dll)
            $iPosY +=2
            DllCall("AutoItX3.dll", "int", "AU3_ControlMove", _
                                    "str", $GuiTitle, _
                                    "str", "", _
                                    "str", $CtrlId2, _
                                    "long", $iPos[0], _
                                    "long", $iPosY, _
                                    "long", 32, _
                                    "long", 32)
            If $iPosY = 500 Then $iPosY = -30
    EndSelect
        DllClose($dll)
EndFunc

Func KeyIsPressed($iHexKey, $sDLL)
    Local $kRet = DllCall($sDLL, "short", "GetAsyncKeyState", _
                                 "int", '0x' & $iHexKey)
    If(@error)Or($kRet) Then Return SetError(1, 0, 0)
    Return BitAND($kRet[0], 0x8000)<>0
EndFunc ;==>End KeyboardControlMoveObject.
Link to comment
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
 Share

  • Recently Browsing   0 members

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