Sign in to follow this  
Followers 0
blinko2008

Need Some help with Mouse/Keyboard functions.

2 posts in this topic

I was playing Clock Tower for the PSX using my pSX v1.13 Emulator and thought..wouldnt it be nice to play a point-n-click game

without using the keyboard or using my USB gamepad?

Well i ran into some trouble..Like if i'm moving my mouse left and changing the X axis..i need the Keyboard to Send("{LEFT}")

same for if i was moving it right the keyboard needs to Send("{RIGHT}")

So basically i'm trying to update the mouse position

and compare it to a set mouse position given from the previous one set before it was moved, and then send the keys accordingly. That way when i move my mouse about the Game Window it'll be moving my Game cursor as well be sending the keyboard keys used to move the cursor for the emulator.Maybe since its white cursor i could use some sort of PixelSearch and see if the pixel color is under the mouse and if it is NOT then locate it and then send the keys to get it there..anyway..Here's the code i'm working with.

CODE
#include <Array.au3>

#include <WinAPI.au3>

#include <Misc.au3>

#include <Mouse.au3>

#include <WindowsConstants.au3>

#include <Constants.au3>

#include <StructureConstants.au3>

; Script Start - Add your code below here

Global $psxEmu, $win_width, $win_height, $winPos, $win_x, $win_y

Global $running,$lastpos,$dist=0,$mp,$newPos

$psxEmu = 'pSX v1.13'

HotKeySet("{F1}","MoveCursor")

HotKeySet("{ESC}","ABORT")

MouseMove(489,375)

SetPos()

Winactivate($psxEmu)

WinWaitActive($psxEmu)

WinMove($psxEmu,'',160,110,656,536,1)

;#include <Misc.au3>

;AdlibEnable("MoveCursor",1)

while WinActive($psxEmu,'')

$winPos = WinGetPos($psxEmu)

;_ArrayDisplay($winPos,"Hmm")

$win_x = $winPos[0]

$win_y = $winPos[1]

$win_width = $winPos[2]

$win_height = $winPos[3]

$win_left = $win_x

$win_right = $win_width + $win_x - 1

$win_top = $win_y + 1

$win_bottom = $win_y + $win_height - 1

;$lastpos = MouseGetPos()

;getpos()

MoveCursor()

WEnd

Func ABORT()

$psxEmu=0

$win_width=0

$win_height=0

$winPos=0

$win_x=0

$win_y=0

$running=0

$lastpos=0

$dist=0

$mp=0

Exit 0

EndFunc

;_arraydisplay($winPos,"ok")

Func getpos()

$lastpos = MouseGetPos()

If $lastpos[0] > $win_left Then

SetPos()

;ExitLoop

else

MouseMove($win_x + 10,$lastpos[1],1)

SetPos()

EndIf

If $lastpos[0] < $win_right Then

SetPos()

else

MouseMove($win_right,$lastpos[1],1)

SetPos()

endif

If $lastpos[1] > $win_top Then

SetPos()

else

MouseMove($lastpos[0],$win_top,1)

SetPos()

endif

If $lastpos[1] < $win_bottom Then

SetPos()

else

MouseMove($lastpos[0],$win_bottom,1)

SetPos()

endif

EndFunc

Func MoveCursor()

Global $mp = MouseGetPos()

Dim $i

ToolTip($mp[0] & ',' & $mp[1],0,0)

If $mp[0] < $newPos[0] Then

for $i = 1 to 100 step 1

Send("{LEFT}")

SetPos()

Next

Else

;$newPos[0] = $mp[0]

;do nothing

EndIf

;else

IF $mp[0] > $newPos[0] Then

for $i = 1 to 100 step 1

Send("{RIGHT}")

SetPos()

Next

Else

;$newPos[0] = $mp[0]

;do nothing

EndIf

If $mp[1] < $newPos[1] Then

for $i = 1 to 100 step 1

Send("{UP}")

SetPos()

Next

Else

;do nothing

EndIf

IF $mp[1] > $newPos[1] Then

for $i = 1 to 100 step 1

Send("{DOWN}")

SetPos()

Next

Else

;do nothing

EndIf

EndFunc

func SetPos()

$newPos = MouseGetPos()

EndFunc

Using AdLibEnabled() function allows the script to work as well as including it within the While.

It's moving my cursor as i move my mouse.But the update is WAY off.

Like if i move my mouse up it goes up then back down. vice versa for all directions.

Sometimes it dont stop other tiems its dead on i dunno what im doing wrong lol ..any ideas?

Share this post


Link to post
Share on other sites



I was playing Clock Tower for the PSX using my pSX v1.13 Emulator and thought..wouldnt it be nice to play a point-n-click game

....

Using AdLibEnabled() function allows the script to work as well as including it within the While.

It's moving my cursor as i move my mouse.But the update is WAY off.

Like if i move my mouse up it goes up then back down. vice versa for all directions.

Sometimes it dont stop other tiems its dead on i dunno what im doing wrong lol ..any ideas?

I think your way of controlling th ecursor is the problem. I suspect it would be easier to have a sort of mouse driven jostick like this.

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <windowsconstants.au3>
#include <screencapture.au3>

;Opt('MustDeclareVars', 1)
Opt("MouseCoordMode", 1)
Opt("PixelCoordMode", 1)
Global $MAXGr = 6, $del
Global $a[$MAXGr + 1]; 0 and $MAXGr entries not used to allow GUICtrlDelete result
Global $child
HotKeySet("{ESC}","quitall");escape route
Example()

Func Example()
    Local $msg, $inc, $i
    Adlibenable("sendkeys",200)
    CreateChild()
    $i = 1
    $inc = 1
    Do
        
                
        $msg = GUIGetMsg()
        Switch $msg
            
            Case $GUI_EVENT_CLOSE
                exit
        EndSwitch
    Until 0
EndFunc  ;==>Example


Func CreateChild()
    
    $child = GUICreate("My Draw", 141, 141, 100, 100);, $WS_POPUP, $WS_EX_LAYERED)
    $del = GUICtrlCreateButton("Delete", 50, 165, 50)


    $a[1] = GUICtrlCreateGraphic(0, 0, 141, 141)
    GUICtrlSetBkColor(-1, 0xababab)
    GUICtrlSetColor(-1, 0xababab)

    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x000000, 0xffff00)
    GUICtrlSetGraphic(-1, $GUI_GR_PIE, 70, 70, 70, -45, 90)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x000000, 0xffffff)
    GUICtrlSetGraphic(-1, $GUI_GR_PIE, 70, 70, 70, 45, 90)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x000000, 0xff0000)
    GUICtrlSetGraphic(-1, $GUI_GR_PIE, 70, 70, 70, 135, 90)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x000000, 0x0000ff)
    GUICtrlSetGraphic(-1, $GUI_GR_PIE, 70, 70, 70, 225, 90)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x000000, 0x000000)
    GUICtrlSetGraphic(-1, $GUI_GR_PIE, 70, 70, 30, 0, 360)
    

    GUISetState()
;_API_SetLayeredWindowAttributes($child, 0xababab, 255)
EndFunc  ;==>CreateChild

Func sendkeys()
    
Local $mp = MouseGetPos()
Local $iPixel = PixelGetColor($mp[0], $mp[1])
Local $wp = WinGetPos($child)

if $mp[0] < $wp[0] or $mp[0] > $wp[0] + $wp[2] or _
     $mp[1] < $wp[1] or $mp[1] > $wp[1] + $wp[3] then return

        switch $iPixel
            case 0xffffff
                Send("{UP}")
            case 0xff0000
                Send("{LEFT}")
            case 0x0000ff
                Send("{DOWN}")
            case 0xffff00
                Send("{RIGHT}")
        EndSwitch
        


EndFunc


Func quitall()
    
exit    
EndFunc

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

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