Jump to content

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


Recommended Posts

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.

Link to comment
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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

_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
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...