Help for newbie randomly choosing text. Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
paulcopeland
Posts: 11
Joined: 04 Jun 2020, 19:26

Help for newbie randomly choosing text.

05 Jun 2020, 06:42

G'day from Australia.

Just yesterday I installed AHK.

Although I have programmed in BASIC, that was way back in around 1980 for the Vic 20.

So, I hope some kind soul can assist. Thank you.

I want to print a random word or sentence to the screen when the user enters the 1 key.
Ultimately there could be thousands of words/sentences that will be printed to the screen.

Here is a screen dump of what I have coded, but I have no idea how to create a random number generator, so that the number generated will send a random word/sentence to the screen.

Please assist and describe the process in very simple language.

Thank you, and hooroo for now.

Paul.

Code: Select all

one() {
	Send, Happy
	Send, {enter}
	}

two() {
	Send, Disparaged 
	Send, {enter}
}

three() {
	Send, You
	Send, {enter}	
}


four() {
	Send, heaviness
	Send, {enter}
}

five() {
	Send, sour
	Send, {enter}	
}

1::one()
2::two()
3::three()
4::four()
5::five()
6::exitapp]
[Mod edit: [code][/code] tags fixed.]
User avatar
elModo7
Posts: 167
Joined: 01 Sep 2017, 02:38
GitHub: elModo7
Location: Spain
Contact:

Re: Help for newbie randomly choosing text.

05 Jun 2020, 07:34

How about:

Code: Select all

#NoEnv
#SingleInstance Force
words := ["cat", "dog", "person", "word", "random"]
1::
Random, value, 1, words.length()
Send, % words[value] " {Enter}"
return
:beer:
paulcopeland
Posts: 11
Joined: 04 Jun 2020, 19:26

Re: Help for newbie randomly choosing text.

05 Jun 2020, 08:10

Thank you so much for such an easy snippet of code.

Best wishes and keep up the great work.

Paul.
User avatar
Chunjee
Posts: 573
Joined: 18 Apr 2014, 19:05
GitHub: Chunjee

Re: Help for newbie randomly choosing text.

05 Jun 2020, 09:00

Code: Select all

A := new biga() ; requires https://www.npmjs.com/package/biga.ahk

1::
Send, % A.sample(["cat", "dog", "person", "word", "random"]) . " {Enter}"
return
posted without comment
paulcopeland
Posts: 11
Joined: 04 Jun 2020, 19:26

Re: Help for newbie randomly choosing text.

06 Jun 2020, 01:01

Hello.

I have download the file that code that was sent to me. It works perfectly.

Now I want to up the ante.

What would like to do is have a timer that runs randomly between 4 to 10 seconds
Every 4-10 seconds, a randomly chosen word/sentence is sent to the screen, instead of entering the 1 key.

Here is the code that was sent to me.

Thank you for your assistance and bye for now.

Paul.


;random word generator from words

#NoEnv
#SingleInstance Force
words := ["cat", "dog", "person", "word", "random"]
1::
Random, value, 1, words.length()
Send, % words[value] " {Enter}"
return


; Instead of the above, I want to have a random timer set which will after a random time of 4-10 seconds
; Send a word/sentence to the screen without any user intervention.

; thank you for your help.
BoBo
Posts: 3263
Joined: 13 May 2014, 17:15

Re: Help for newbie randomly choosing text.

06 Jun 2020, 01:19

Code: Select all

#Persistent    ; run timer constantly
#NoEnv
#SingleInstance Force
words := ["cat", "dog", "person", "word", "random"]

SetTimer, WordsOfWisdom, 1000
Return

WordsOfWisdom:
    Random, delay, 3, 9   ; add some time 3-9s
    Random, value, 1, words.length()
    Sleep, delay * 1000
    Send, % words[value] " {Enter}"
    return
    
F12::SetTimer, WordsOfWisdom, Off    ; let's have a break!
paulcopeland
Posts: 11
Joined: 04 Jun 2020, 19:26

Re: Help for newbie randomly choosing text.  Topic is solved

06 Jun 2020, 01:27

Thank you for your quick response.

When I run the script nothing appears on Notepad.

Sorry, if I am the dummy of the day, but could you please help me get output?

Many thanks.

Paul.

___________________________

Code: Select all

#Persistent    ; run timer constantly
#NoEnv
#SingleInstance Force
words := ["cat", "dog", "person", "word", "random"]


SetTimer, WordsOfWisdom, 1000
Return

WordsOfWisdom:
    Random, delay, 3, 9   ; add some time 3-9s
    Random, value, 1, words.length()
    Sleep, delay * 1000
    Send, % words[value] " {Enter}"
    return
BoBo
Posts: 3263
Joined: 13 May 2014, 17:15

Re: Help for newbie randomly choosing text.

06 Jun 2020, 01:39

Please use code-tags from now on. Thx!

Can't see why it shouldn't do it, except that you haven't set the focus (back) to Notepad's edit screen??
Start the script and click on your open Notepad window. There's nothing more I can say ATM :)

PS. why it's necessary to paste those words into Notepad? Why not simply display them using a :arrow: ToolTip or a :arrow: GUI ??
paulcopeland
Posts: 11
Joined: 04 Jun 2020, 19:26

Re: Help for newbie randomly choosing text.

06 Jun 2020, 01:54

Thank you so much BoBo.

Working perfectly now.

Best wishes and keep up the great work.

Paul. :D

Return to “Ask For Help”

Who is online

Users browsing this forum: boiler, frosse, Google [Bot], malcev, navmesh, teadrinker, Zamfir and 73 guests