Sign in to follow this  
Followers 0
ChronoStriker1

press a button to simulate mouse click only when prog is running

6 posts in this topic

What I want to do is press a keyboard button to move the mouse, click a button so I can zoom in a medical program, then move back to the original position. I also want it to only happen while the program is running.

This is a test script for what I want to do. I'm using firefox as the program cause I don't have the medical program on my laptop.

#RequireAdmin
#Include <Misc.au3>

$dll = DllOpen("user32.dll")

While 1
    Sleep(10)
    If _IsPressed("7B", $dll) Then
        If ProcessExists("firefox.exe") Then ;change when I find out process name
            $origpos = MouseGetPos()
            MouseClick("left", 0, 0, 1, 10) ;change 10 to 1 so its instant
            MouseMove($origpos[0], $origpos[1], 10) ;same as above
        EndIf
    EndIf
WEnd

DllClose($dll)

Is this the best way to do this and is there anyway to map it to the "?" button, I didn't see hex for it.

Share this post


Link to post
Share on other sites



I think you want a hotkey. If that is true then

#RequireAdmin
#Include <Misc.au3>

$dll = DllOpen("user32.dll")
Hotkeyset ("your key", "_zoom"

Func _zoom ()

;your program here

Endfunc

While 1
Sleep (1000)
Wend

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

You'd be better off using a hotkey probably. Look up HotKeySet() in the helpful. Your code will turn into something like:

HotKeySet("yourkey","yourfunction")
HotKeySet("exitkey","Terminate")

Func yourfunction()
 ;mouse moving and clicking code goes here
EndFunc

Func Terminate()
   exit 0
EndFunc

While 1
   sleep(10)
WEnd

To use "?" as your hotkey, you can simply put "?" or "+/" since they're equivalent.

Edited by Leighwyn

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

_IsPressed should work

you can clean up your code if you used ControlClick (no mouse movement)

Put it in a function

EDIT: Hotkey will work fine, but unless you see the FAQ and tweak the example a bit, whatever key you use for your hotkey will no longer be able to be used. In other words, if "?" is your hotkey then you would not be able to type a "?" into any other program (without seeing the FAQ)

Edited by danwilli

Share this post


Link to post
Share on other sites

I originally used HotKeySet but it ran regardless of the process being found or not.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

then put the If processexists into the function

EDIT: Please see above comments about HotKeySet

Edited by danwilli

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