Jump to content

Creating simple script with hotkey


Go to solution Solved by AlessandroAvolio,

Recommended Posts

Hi, 

i created a simple script that send's a text when you press F1. The problem is there is html code inside and its interfering with the Autoit code itself. How do i make it so Autoit ignores the code and just pastes the text like a normal text? 

Thanks

 

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

While 1
    Sleep(100)
WEnd

Func SendMe()
    Send("- Sehr flexibel")
    Send("{Enter}")
    Send("- Rundum Schutz")
    Send("{Enter}")
    Send("- Rückseite druckbar")
    Send("{Enter}")
    Send("<p style="text-align: left;"><a href="https://www.anchorcase.de/soft-case/" target="_blank" rel="noopener">Mehr Infos zum Produkt</a></p>")
EndFunc

 

Link to post
Share on other sites
  • Solution

https://www.autoitscript.com/autoit3/docs/intro/lang_datatypes.htm

Quote

Strings

Strings are enclosed in double-quotes like "this". If you want a string to actually contain a double-quote use it twice like:

"here is a ""double-quote"" - ok?"

You can also use single-quotes like 'this' and 'here is a ' 'single-quote' ' - ok?'

 

You can mix quote types to make for easier working and to avoid having to double-up your quotes to get what you want. For example if you want to use a lot of double-quotes in your strings then you should use single-quotes for declaring them:

'This "sentence" contains "lots" of "double-quotes" does it not?'

is much simpler than:

"This ""sentence"" contains ""lots"" of ""double-quotes"" does it not?"

 

Link to post
Share on other sites

Cool, that worked, thanks

 

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

While 1
    Sleep(100)
WEnd

Func SendMe()
    Send("- Sehr flexibel")
    Send("{Enter}")
    Send("- Rundum Schutz")
    Send("{Enter}")
    Send("- Rückseite druckbar")
    Send("{Enter}")
    Send('"<p style="text-align: left;"><a href="https://www.anchorcase.de/soft-case/" target="_blank" rel="noopener">Mehr Infos zum Produkt</a></p>"')
EndFunc

 

Link to post
Share on other sites

Regarding Opt("SendKeyDelay, ...) " : Even with value 0 there is still a bit of a delay (at least on my system). 

The suggestion by @Danp2 ("Place the text on the clipboard and then send Ctrl+V to paste.") works without delay.

Example :

Opt("SendKeyDelay", 0)
Local $sText = "Write text into line 01 of the editor window" & @CRLF & _
               "Write text into line 02 of the editor window" & @CRLF & _
               "Write text into line 03 of the editor window" & @CRLF & _
               "==> wait 2 seconds" & @CRLF

; To visiualize, run Notepad with the window maximized.
Local $iPID = Run("notepad.exe", "", @SW_SHOWMAXIMIZED)
WinWait("[CLASS:Notepad]", "", 10)

; 1 . :
Send($sText)
Sleep(2000)
; Clear Window :
Send("^a")
Sleep(500)
Send("{DEL}")
Sleep(1000)

; 2. Retrieves text from the clipboard
ClipPut($sText)
Send("^v") ; paste via CTRL+V
Sleep(2000)

; Close the Notepad process using the PID returned by Run.
ProcessClose($iPID)
ConsoleWrite("Close the Notepad process" & @CRLF)

 

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to post
Share on other sites

The only solution for this is to make Autoit write the text and then copy and paste it ? There is no option to paste it right away without the text animation? 

For example this is done with macro tool: https://streamable.com/eccofk
The only problem is it does only support one line of text per hotkey, so i dont want to press 4 keys after another. Everything should be pasted with just one click mouse click.

 

Thanks

Edited by liam0002
Link to post
Share on other sites
1 hour ago, liam0002 said:

The only solution for this is to make Autoit write the text and then copy and paste it ? There is no option to paste it right away without the text animation? 

For example this is done with macro tool: https://streamable.com/eccofk
The only problem is it does only support one line of text per hotkey, so i dont want to press 4 keys after another. Everything should be pasted with just one click mouse click.

 

Thanks

You can with ClipPut() and Send("^v")

https://www.autoitscript.com/autoit3/docs/functions/ClipPut.htm

 

Main()

Func Main()

    ClipPut("123123123123123123123123123123123123123123" _
    & "123123123123123123123123123123123123123123" _
    & "123123123123123123123123123123123123123123" _
    & "123123123123123123123123123123123123123123" _
    & "123123123123123123123123123123123123123123" _
    & "123123123123123123123123123123123123123123" _
    & "123123123123123123123123123123123123123123" _
    & "123123123123123123123123123123123123123123" _
    & "123123123123123123123123123123123123123123" _
    & "123123123123123123123123123123123123123123" _
    & "123123123123123123123123123123123123123123" _
    & "123123123123123123123123123123123123123123" _
    & "123123123123123123123123123123123123123123" _
    & "123123123123123123123123123123123123123123" _
    & "123123123123123123123123123123123123123123" _
    & "123123123123123123123123123123123123123123" _
    & "123123123123123123123123123123123123123123" _
    & "123123123123123123123123123123123123123123" _
    & "123123123123123123123123123123123123123123" _
    & "123123123123123123123123123123123123123123" _
    & "123123123123123123123123123123123123123123" _
    & "123123123123123123123123123123123123123123" _
    & "123123123123123123123123123123123123123123")

    Send("^v")


EndFunc

 

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

You can with ClipPut() and Send("^v")

Just out of curiosity (maybe I'm missing something) : How does this differ from my code snippet ?

[...]
; 2. Retrieves text from the clipboard
ClipPut($sText)
Send("^v") ; paste via CTRL+V
[...]

 

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to post
Share on other sites

If possible then you can use ControlSetText() instead of Send() to avoid "animation effects".

- as window title use "[active]" for actual active window

- as ControlID use empty string to set text of focused control inside target window

ControlSetText('[active]','','','my text to send')

 

Edited by Zedna
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...