Harmless Prank

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
thegame2010
Posts: 29
Joined: 04 Feb 2016, 18:14
Location: 'Murica

Harmless Prank

Post by thegame2010 » 24 Feb 2016, 13:23

I wrote up a little code which would replace "e" with ":D" 1% of the time. It doesn't work. See below.

Code: Select all

list1= e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, :D
listA:=strSplit(list1, ",") ; A = Array

~e:: 
	random, choice, 1, % listA.maxIndex() 
	response:=trim(listA[choice]) 
	sendRaw, %response% 
return 
Instead, it runs itself over and over (Sending "e," of course, triggers the hotkey) until it's a smiley. I can think of 2 options to fix this, which I'm looking up now:
A) There's a better option than sendRaw which would input the keystroke without triggering the hotkey again.
B) There's a way to have it produce a random number between 1 and 100, and if it's 1 then it sends a smiley. Else it does nothing.

I'm more a fan of the second option, but I bet the first one will be way faster and easier (if it's possible). What do you think?
wizardzedd
Posts: 319
Joined: 23 Jan 2016, 23:03

Re: Harmless Prank

Post by wizardzedd » 24 Feb 2016, 14:23

Use the $ symbol to prevent send from triggering hotkeys . Also, why the array? Seems like a waste of space.

Code: Select all

$e:: 
	random, choice, 1, 100 
	if(choice = 1)
		send, :D
	else
		send, e
return 
User avatar
thegame2010
Posts: 29
Joined: 04 Feb 2016, 18:14
Location: 'Murica

Re: Harmless Prank

Post by thegame2010 » 24 Feb 2016, 15:28

I'm only just learning ahk, and it seemed to work. This is much more concise. Thank you. It is working much better than the oth:Dr way.
Post Reply

Return to “Ask for Help (v1)”