Jump to content
Hewittdude303

Pressing the left or right arrow after keys are pressed

Recommended Posts

Hello everyone, I have just started using AutoIt so my knowledge is very basic. I have been really wanting to use it to automate part of my job. The program I work in is in google chrome and I have to enter text and numbers letter by letter, and advance manually using the left or right arrow keys, as sometimes the text I need to enter has to be entered from right to left. I was hoping I could have a script that runs continuously in the background, and every time I press a key is would automatically press the left or right arrow key. I would like to be able to specify what key it presses before I enter my text by pressing the left or right arrow keys myself. If I press the right arrow key it will advance right, and vice versa. It would also be handy for me to be able to pause and unpause the script using the backslash key. I'm sure something like this is possible, but at my current knowledge level I have no clue how to make something like this. Can one of you help me out here? It would be greatly appreciated. 

Share this post


Link to post
Share on other sites
Posted (edited)
30 minutes ago, Hewittdude303 said:

Can one of you help me out here?

What exactly do you mean by "help me out here"?  Are you asking for help in learning AutoIt in order for you to be able to write your own script or are you asking for someone to write it for you?  If it is the former, then what issue are you having a problem with or need a better understanding of?

Edited by TheXman

Share this post


Link to post
Share on other sites
9 minutes ago, TheXman said:

What exactly do you mean by "help me out here"?  Are you asking for help in learning AutoIt in order for you to be able to write your own script or are you asking for someone to write it for you?

I would prefer to learn how to write something like this myself, but if something like this is too complicated to explain easily someone can write it for me. 

Share this post


Link to post
Share on other sites

How is someone supposed to know what is "too complicated" for you to understand?  Why don't you show us what you have come up with so far so we can see and understand where you are in your AutoIt abilities and understanding.  If you haven't come up with anything yet, then come back when you've taken the time to learn more about the basics and have something to build upon.

As far as having someone write it for you, as someone new to AutoIt, that's just plain disrespectful to all of the people who have not taken such shortcuts and have taken the time to learn the language and become proficient at it.  Although there are some in this forum that will probably write it for you, I certainly am not one of them.  However, if you are truly interested in learning the language, I would be more than happy to assist you.

Share this post


Link to post
Share on other sites
4 minutes ago, TheXman said:

How is someone supposed to know what is "too complicated" for you to understand?  Why don't you show us what you have come up with so far so we can see and understand where you are in your AutoIt abilities and understanding.  If you haven't come up with anything yet, then come back when you've taken the time to learn more about the basics and have something to build upon.

As far as having someone write it for you, as someone new to AutoIt, that's just plain disrespectful to all of the people who have not taken such shortcuts and have taken the time to learn the language and become proficient at it.  Although there are some in this forum that will probably write it for you, I certainly am not one of them.  However, if you are truly interested in learning the language, I would be more than happy to assist you.

I did not mean to be disrespectful to you and everyone here on this forum. I completely understand what you are talking about here, and I am truly interested in learning about this program and how to use it. I am majoring in mechatronics and learning anything coding related is going to be beneficial to me. What I meant is if taking the time to explain everything to me would be more trouble than just writing the thing yourself than you do not have to explain it all to me.  

Share this post


Link to post
Share on other sites

That is enough begging for one day, don't you think ?  As it was told to you, show some effort and provide a basic script if you want anybody here to help you.

Share this post


Link to post
Share on other sites
Posted (edited)
54 minutes ago, Hewittdude303 said:

What I meant is if taking the time to explain everything to me would be more trouble than just writing the thing yourself than you do not have to explain it all to me. 

I do not totally understand the requirements of your script as stated.  Given how new you are to AutoIt, it will definitely be more "trouble" and time-consuming for me to help you learn the skills needed to write your script than it would take for me to write it.  To me, an ex-CTO, it is my belief that the time taken to help someone learn a new skill so that they can become self-sufficient -- no matter how tedious -- is much more beneficial and rewarding than just providing them answers that they can't understand or maintain.  Of course, this assume that the person truly wants to learn those new skills and has the aptitude to do so.

I guess the choice is yours now.  You can continue to ask and wait for someone to write the script you are looking for or you can start learning AutoIt so that you can write this and any other scripts that you may need in the future.  If you choose to learn AutoIt, there are numerous people here, including myself, that will help you overcome any obstacles that you may encounter.

Edited by TheXman

Share this post


Link to post
Share on other sites
Posted (edited)

Alright, I have done some work on this. I based it off of the basic example in the _IsPressed info section as I thought that would be a good starting point. I did some modification to get it to move over when I pressed the L key, but unfortunately the program will only enter L once the key is released. I tried to fix this by adding the sleep function so I could get a delay between when I pressed the key and when I lifted it so it would type the L and then move over. Sadly that did not work. I need something that will check to see if the _IsPressed function is false and then if so press the right arrow. I'm thinking an If...ElseIf...Else...EndIf statement might work. What do you guys think? Attached is what I have so far.

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.14.5
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here
#include <Misc.au3>
#include <MsgBoxConstants.au3>
Local $hDLL = DllOpen("user32.dll")
While 1
    If _IsPressed("4C", $hDLL) Then
        Sleep(1)
        Send("{RIGHT}")
    ElseIf _IsPressed("1B", $hDLL) Then
        MsgBox($MB_SYSTEMMODAL, "_IsPressed", "The Esc Key was pressed, therefore we will close the application.")
        ExitLoop
    EndIf
    Sleep(250)
WEnd

Next key press.au3

Edited by Jos
just post code inline with <>

Share this post


Link to post
Share on other sites
Posted (edited)
2 hours ago, Hewittdude303 said:

The program I work in is in google chrome and I have to enter text and numbers letter by letter, and advance manually using the left or right arrow keys, as sometimes the text I need to enter has to be entered from right to left.

What is the name and/or URL of this web app?  In general, automating web apps is a bit different than automating desktop apps.

Like I said before, I don't have a good understanding of what you are trying to achieve.  It sounds similar to a keylogger, which would is a topic that is prohibited.  Can you give a better explanation of what it is you are looking for and maybe an example?

Why when you press "L", why would you want to send the right arrow?  If you enter letters and numbers into this application, "L" is never going to be one of the letters that you would normally enter?  Or are you trying to simulate entering data from right to left, so that when you enter a letter, you move the cursor to the left of that character?   If so, is this right to left entry for all characters or just a certain set of characters?  This doesn't make sense and needs a better explanation.

 

Edited by TheXman

Share this post


Link to post
Share on other sites

Also take a look at _WinAPI_SetWindowsHookEx in help file.  There is a great example of how to intercept keys.  If you need to check for multiple keys, this might be a better solution for you than using _IsPressed.

 

Share this post


Link to post
Share on other sites
On 8/6/2020 at 2:48 PM, TheXman said:

What is the name and/or URL of this web app?  In general, automating web apps is a bit different than automating desktop apps.

Like I said before, I don't have a good understanding of what you are trying to achieve.  It sounds similar to a keylogger, which would is a topic that is prohibited.  Can you give a better explanation of what it is you are looking for and maybe an example?

Why when you press "L", why would you want to send the right arrow?  If you enter letters and numbers into this application, "L" is never going to be one of the letters that you would normally enter?  Or are you trying to simulate entering data from right to left, so that when you enter a letter, you move the cursor to the left of that character?   If so, is this right to left entry for all characters or just a certain set of characters?  This doesn't make sense and needs a better explanation.

 

The web app is called VisioStack Applications, what I'm doing is surrounding individual letters from images of railroad tracks with bounding boxes and typing in what that letter is. I have made a basic representation of what the interface looks like, since I do not want to take a screenshot of the actual interface. I used the letter L just for the purposes of testing out my script. You move between the bounding boxes with the arrow keys, so it would be much faster to have this automated instead of having to press the arrow key between typing every letter. I have also worked on my script a bit and it works partially, if you press the keys too quickly it doesn't respond so you have to type methodically and it really slows you down. I've tried playing with the sleep times and that didn't fix the issue. I'm sure there is a way to improve the response times, do you have any suggestions?

AI Representation.png

Next key press L.au3

Share this post


Link to post
Share on other sites
Posted (edited)

Looking at your script and the description of what you are looking to do in your initial post, I think using HotKeySet may be a better route.  The example that I have supplied below only monitors the "L" key (both upper and lower case).  Meaning, if the app is not paused and the "L" is typed, the right or left arrow key will be entered.  Pressing ESC will exit the app.  Pressing "|" will pause the app.  Pressing "\" will change the direction of the arrow key that is enter.  Pressing any of those hotkeys will also show a tray tip to show the current status.  Hovering over the app's tray icon will also show the current status.  Since I still really do not understand what you are trying to do, hopefully this will help give you something to build upon.

Note that the "L" will not be sent, it will just move left or right depending on the current state of the app.  I specifically wrote it that way because that is how I interpreted your description.

Spoiler
#AutoIt3Wrapper_AU3Check_Parameters=-w 3 -w 4 -w 5 -w 6 -d
#include <Constants.au3>

Global $gbPauseEnabled = False, $gbArrowLeft = True
Global $gsTrayTipMsg  = ""

;Monitored Keys
HotKeySet("{esc}", exit_script)             ;Press ESC to exit script
HotKeySet("|"    , toggle_pause)            ;Press | to toggle pause state
HotKeySet("\"    , toggle_arrow_direction)  ;Press \ to toggle arrow direction for monitored keys
HotKeySet("l"    , send_arrow_key)
HotKeySet("L"    , send_arrow_key)


;Display tray tip and launch message
show_tray_tip()
MsgBox($MB_TOPMOST + $MB_ICONINFORMATION, "Arrow Key Example", _
       "Press ESC to Exit." & @CRLF & _
       "Press | to toggle pausing the app." & @CRLF & _
       "Press \ to toggle arrow advancement.")

;Loop endlessly to keep script active
While 1
    Sleep(10)
WEnd

;==============   Functions   ==============

Func send_arrow_key()
    If Not $gbPauseEnabled Then Send(($gbArrowLeft ? "{left}" : "{right}"))
EndFunc

Func toggle_arrow_direction()
    $gbArrowLeft = Not $gbArrowLeft
    show_tray_tip()
EndFunc

Func toggle_pause()
    $gbPauseEnabled = Not $gbPauseEnabled
    show_tray_tip()
EndFunc

Func show_tray_tip()
    $gsTrayTipMsg =  "ESC to Exit" & @CRLF
    $gsTrayTipMsg &= "(|) Paused = " & ($gbPauseEnabled ? "True" : "False") & @CRLF
    $gsTrayTipMsg &= "(\) Arrow direction =  " & ($gbArrowLeft ? "Left" : "Right")
    TraySetToolTip($gsTrayTipMsg)
    TrayTip("Arrow Key Example", $gsTrayTipMsg, 3, $TIP_ICONASTERISK)
EndFunc

Func exit_script()
    Exit
EndFunc

 

 

Edited by TheXman

Share this post


Link to post
Share on other sites
Posted (edited)

Maybe I'm misunderstanding, but couldn't you take input from the user, reverse the text if needed (handling your strange right to left typing), and slowly send it to the App?

Edit: Please note that Sleep(1) will pause the code for 1/1000 of a second... probably not what you're looking for :D

Spoiler

 

#include <GUIConstants.au3>

Global $hGUI = GUICreate("VisioStack Input", 340, 120, 192, 124)
Global $idCancel = GUICtrlCreateButton("Cancel", 160, 75, 75, 25)
Global $idOK = GUICtrlCreateButton("OK", 25, 75, 75, 25)
Global $idInput = GUICtrlCreateInput("Input1", 65, 15, 256, 21)
GUICtrlCreateLabel("Text", 25, 15, 36, 17)
Global $idReverse = GUICtrlCreateCheckbox("Reverse Text", 25, 45, 97, 17)
GUISetState(@SW_SHOW)

Main()

Func Main()

    Local $sText

    While True
        Switch GUIGetMsg()
            Case $idOK
                $sText = GUICtrlRead($idInput)
                If $sText = "" Then ContinueLoop
                If GUICtrlRead($idReverse) = $GUI_CHECKED Then
                    $sText = StringReverse($sText)
                EndIf

                ; Do your send stuff here
                SendKeepActive("Untitled - Notepad")
                For $i=1 To StringLen($sText)
                    Send(StringMid($sText, $i, 1))
                    Sleep(1000)
                Next
                SendKeepActive("")

            Case $GUI_EVENT_CLOSE, $idCancel
                ExitLoop
        EndSwitch
    WEnd

    GUIDelete($hGUI)

EndFunc
Edited by seadoggie01

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts

Share this post


Link to post
Share on other sites
Just now, seadoggie01 said:

Maybe I'm misunderstanding

Join the club.  I still don't understand exactly what was requested either.  :muttley:  I just created an example based on his attempt.

Share this post


Link to post
Share on other sites

Wow, thank you so much. You are amazing. I would have never have been able to make something so complicated. I will have to see what I can do off of this. It never occurred to me to use functions, hahah. 

2 hours ago, TheXman said:

Looking at your script and the description of what you are looking to do in your initial post, I think using HotKeySet may be a better route.  The example that I have supplied below only monitors the "L" key (both upper and lower case).  Meaning, if the app is not paused and the "L" is typed, the right or left arrow key will be entered.  Pressing ESC will exit the app.  Pressing "|" will pause the app.  Pressing "\" will change the direction of the arrow key that is enter.  Pressing any of those hotkeys will also show a tray tip to show the current status.  Hovering over the app's tray icon will also show the current status.  Since I still really do not understand what you are trying to do, hopefully this will help give you something to build upon.

Note that the "L" will not be sent, it will just move left or right depending on the current state of the app.  I specifically wrote it that way because that is how I interpreted your description.

  Reveal hidden contents
#AutoIt3Wrapper_AU3Check_Parameters=-w 3 -w 4 -w 5 -w 6 -d
#include <Constants.au3>

Global $gbPauseEnabled = False, $gbArrowLeft = True
Global $gsTrayTipMsg  = ""

;Monitored Keys
HotKeySet("{esc}", exit_script)             ;Press ESC to exit script
HotKeySet("|"    , toggle_pause)            ;Press | to toggle pause state
HotKeySet("\"    , toggle_arrow_direction)  ;Press \ to toggle arrow direction for monitored keys
HotKeySet("l"    , send_arrow_key)
HotKeySet("L"    , send_arrow_key)


;Display tray tip and launch message
show_tray_tip()
MsgBox($MB_TOPMOST + $MB_ICONINFORMATION, "Arrow Key Example", _
       "Press ESC to Exit." & @CRLF & _
       "Press | to toggle pausing the app." & @CRLF & _
       "Press \ to toggle arrow advancement.")

;Loop endlessly to keep script active
While 1
    Sleep(10)
WEnd

;==============   Functions   ==============

Func send_arrow_key()
    If Not $gbPauseEnabled Then Send(($gbArrowLeft ? "{left}" : "{right}"))
EndFunc

Func toggle_arrow_direction()
    $gbArrowLeft = Not $gbArrowLeft
    show_tray_tip()
EndFunc

Func toggle_pause()
    $gbPauseEnabled = Not $gbPauseEnabled
    show_tray_tip()
EndFunc

Func show_tray_tip()
    $gsTrayTipMsg =  "ESC to Exit" & @CRLF
    $gsTrayTipMsg &= "(|) Paused = " & ($gbPauseEnabled ? "True" : "False") & @CRLF
    $gsTrayTipMsg &= "(\) Arrow direction =  " & ($gbArrowLeft ? "Left" : "Right")
    TraySetToolTip($gsTrayTipMsg)
    TrayTip("Arrow Key Example", $gsTrayTipMsg, 3, $TIP_ICONASTERISK)
EndFunc

Func exit_script()
    Exit
EndFunc

 

 

 

Share this post


Link to post
Share on other sites

I certainly has and I cannot thank you enough. I am certainly interested in learning more about this program and I look forward to being able to use this to further automate the entire process of my text entry. This will be fun!

Share this post


Link to post
Share on other sites
22 hours ago, TheXman said:

Thanks, I hope that it ends up being useful for you.  If nothing else, I hope it sparks your interest in continuing to learn AutoIt and all of its capabilities.  :thumbsup:

You're welcome, and it certainly has; I cannot thank you enough. I am certainly interested in learning more about this program and I look forward to being able to use this to further automate the entire process of my text entry. This will be fun!

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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...