Jump to content

Sending keyboard & mouse clicks


dr4ckerz
 Share

Recommended Posts

First of all, hello to all the good people who came to my thread to help me out and answer my questions. This is my first day of autoit and trying to learn it from a blank page you get at the beginning. I figured a good way to start is learning how to automate my mouse and keyboard (sending keys and clicks), I would also like to have a start/stop script key. Possibly also a loop to endlessly send the key or clicks and stop it with a key toggle, but that's for later because right now even the first step is not working out for me :) I looked around and googled for about an hour, came up with some code but it doesn't seem to be working.

 

HotKeySet("d", "_dfgh")



Func _dfgh()
    Send("{dfgh}")
EndFunc

What I'm trying to do is send "d","f","g","h" every time I start the function _dfgh - and this should be done every time I press "d". There shouldn't be a time limit except if I turn the entire script off with a toggle (I obviously don't know how to do that, next step! :) )

Link to comment
Share on other sites

Welcome to the AutoIT forums - To start off you have to call your function _dfgh() in order for it to run correctly. 

_dfgh() ;<<<< To run function

Func _dfgh() ; function 
    Send("{dfgh}") ; dfgh will not work! Only "d" is be typed out.
EndFunc ; end function

I would suggest reading this forum another person posted about  "Key Presses".

#include <Misc.au3> ; <-- I would read the #include to further understand what #include does.
                    ; https://www.autoitscript.com/autoit3/docs/keywords/include.htm

$dll = DllOpen("user32.dll") ; <-- I would read this to further understand how to use DLL's
                             ; https://www.autoitscript.com/autoit3/docs/functions/DllOpen.htm

While 1
    Sleep ( 50 )
    If _IsPressed("KEY WILL GO HERE!", $dll) Then
        MsgBox(0,"_IsPressed", "End Key Pressed")
        ExitLoop
    EndIf
WEnd
DllClose($dll)

The above is an example out of the link from above. I added some comments that you should research and expand your knowledge on!

 

Edited by aa2zz6
Link to comment
Share on other sites

HotKeySet("^d", "_dfgh") ;ctrl and d. using a key you are sending will render you in an awkward loop

While 3
    Sleep(333)
;keep script alive
WEnd    

Func _dfgh()
    Send("{dfgh}")
EndFunc

 

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Oh maybe I'm being influenced by learning a bit autohotkey prior to this. For instance what I would do in autohotkey would be:

 

~d::

send, fgh

With just this I would be able to send "dfgh" every time I pressed "d" without causing an infinite loop, but being able to press it infinitely. Do you mind telling me the equivalent in autoit? It would really help my learning process to see the equivalence. Thanks!

Link to comment
Share on other sites

If you only want to send fgh, use this (or add in the d on the send)...if you DON'T want to wait for the control to be unpressed, then delete the first 2 _isPressed:

Run("Notepad")

HotKeySet("^d", "_dfgh") ;ctrl and d. using a key you are sending will render you in an awkward loop

While 3
    Sleep(333)
;keep script alive
WEnd



Func _dfgh()
    While _IsPressed("A2") Or _IsPressed("A3") Or _IsPressed("44")
    WEnd

    Send("fgh")
EndFunc

Actually, this works well:

Run("Notepad")

HotKeySet("^d", "_dfgh") ;ctrl and d. using a key you are sending will render you in an awkward loop

While 3
    Sleep(333)
;keep script alive
WEnd



Func _dfgh()
    While (_IsPressed("A2") Or _IsPressed("A3")) And _IsPressed("44")
    WEnd

    Send("fgh")
EndFunc

 

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

I'm sorry but this doesn't work for me. If it worked then I could research and make modifications to it or apply what I learned on this for future scripts that resemble it. But starting from a blank page and no working scripts is a bit hard, seems autoit is harder than AHK.

 

 

2015-12-29_23-47-42.png

Link to comment
Share on other sites

@dr4ckerz -    The people behind autoit made a very good help file for every newbie can learn by self study.  At first, you may feel some muddiness. But you will slowly get the point. So keep in mind that every time your code fails to run, don't aproach the forum. A simple solution for that problem is described in the help file. I am sure. Read it carefully. You will find the solution. But if you can't get it from the help file after a few attempts, then think about posting your question here. Why i am saying this because, i know the help file is treasure for a newbie. Happy coding.

Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

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