Hey, i forgot to login the first time i made this thread so i dont know if im posting this twice. I cant see it in the forum so far.
Im completly new to AHK, so when i try to search with google i understand almost nothing because its too advanced.
I know how to edit, run and compile a script.
What i need is a script that, whenever i press TAB, it opens a Message Window with a random chance (for example every 1 in 800 times) with a certain text. 799 in 800 times nothing happens.
Even better would it be if the 799 times there is a message too, the problem is that i dont wanna have a standard windows message window opened those times. Is there a way to show a message without windows message that takes focus?
Can someone help me with that? I would really be thankful for a code that i just have to copy and edit later (i wanna change probabilty later and maybe the hotkey).
Thanks in advance!
Message with random probability when pressing a button
Re: Message with random probability when pressing a button
Give it your best shot. These documents should let you figure out what you need to do:
Hotkey
Random
If and operators
else
(Optionally, Blocks for the if/else statements.)
MsgBox and Tooltip (as ways to display your message)
return ; signals the end of a hotkey
I recommend you use Random to generate a number between 1 and 800, then use an if statement to check if it equals a single number. (There's a 1/800 chance that it would.)
If you have read through those and pieced together a script that still doesn't seem to be working, can you share what you came up with and we can guide you in solving it? I think it'll be best for you to learn making something up from scratch in this case, which will then be easier for you to modify as you start to see how things work.
Hotkey
Random
If and operators
else
(Optionally, Blocks for the if/else statements.)
MsgBox and Tooltip (as ways to display your message)
return ; signals the end of a hotkey
I recommend you use Random to generate a number between 1 and 800, then use an if statement to check if it equals a single number. (There's a 1/800 chance that it would.)
If you have read through those and pieced together a script that still doesn't seem to be working, can you share what you came up with and we can guide you in solving it? I think it'll be best for you to learn making something up from scratch in this case, which will then be easier for you to modify as you start to see how things work.
Re: Message with random probability when pressing a button
Now that i see it, a tooltip would probably be perfect for me for showing the message
Re: Message with random probability when pressing a button
Tab::
Random Num, 1, 3
if (Num = 1) {
Send % Num
}
This is what i have so far. i use 1-3 so i can check better if its working. How do i get it into a tooltop instead of sending?
Random Num, 1, 3
if (Num = 1) {
Send % Num
}
This is what i have so far. i use 1-3 so i can check better if its working. How do i get it into a tooltop instead of sending?
Re: Message with random probability when pressing a button
by using ToolTip instead of send
you also forgot the important "return" at the end.
you also forgot the important "return" at the end.
rawr. fear me.
*poke*
Is it December 21, 2012 yet?
*poke*
Is it December 21, 2012 yet?
Re: Message with random probability when pressing a button
Edit:
Tab::
Random Num, 1, 3
if (Num= 1) {
MsgBox, , Title, Text,
}
else {
ToolTip Message, , , 1
}
sleep 1000
ToolTip, , , , 1
return
Its perfect like this. I get a message box only when i hit the 1/3 (or 1 in 800 later).
Only 1 thing lefti cant figure out. How do i make it possible that multiple tooltips can view at once? I want them to dissapear automatically (it already does), but i cant get a new tooltip until the old one dissappeared. It probably has to do with WhichToolTip, but i dont know how to apply it. Can anyon please help me?
Tab::
Random Num, 1, 3
if (Num= 1) {
MsgBox, , Title, Text,
}
else {
ToolTip Message, , , 1
}
sleep 1000
ToolTip, , , , 1
return
Its perfect like this. I get a message box only when i hit the 1/3 (or 1 in 800 later).
Only 1 thing lefti cant figure out. How do i make it possible that multiple tooltips can view at once? I want them to dissapear automatically (it already does), but i cant get a new tooltip until the old one dissappeared. It probably has to do with WhichToolTip, but i dont know how to apply it. Can anyon please help me?
Re: Message with random probability when pressing a button
Nevermind. Its ok when the tooltip dissapears when i click the button again.
Actually this is really cool, exactly what i need. Thanks for your help.
Actually this is really cool, exactly what i need. Thanks for your help.
Re: Message with random probability when pressing a button
Ok 1 more thing:
I have it like this now:
Tab::
Random Num, 1, 600
if (Num= 1) {
MsgBox, , this is a title!,blablabla,
}
else {
ToolTip blablablabla, , , 1
}
return
When i click tab a new tooltip opens. If i close the tooltip with a command (empty tooltip) after a certain time, i cant open a new tooltip before that time is over.
Is there a way to get both? Get a new one when i click tab again, but if i dont, it closes in lets say 20 seconds?
I have it like this now:
Tab::
Random Num, 1, 600
if (Num= 1) {
MsgBox, , this is a title!,blablabla,
}
else {
ToolTip blablablabla, , , 1
}
return
When i click tab a new tooltip opens. If i close the tooltip with a command (empty tooltip) after a certain time, i cant open a new tooltip before that time is over.
Is there a way to get both? Get a new one when i click tab again, but if i dont, it closes in lets say 20 seconds?
Re: Message with random probability when pressing a button
Include this in your else block when a tooltip is shown: SetTimer, HideTip, -20000 ; milliseconds. Then add this to the bottom of your script (after the return you currently have):
No parameters on the tooltip command will hide (or clear) the one that is shown. And I believe this should work for your purposes.
Also, if you wrap your code in
Code: Select all
HideTip:
Tooltip
return
Also, if you wrap your code in
Code: Select all
tags, that makes it a bit easier for us to see at a glance which parts of posts are code.
(Edit: Thanks smarq8 below; I forgot negative values were a thing for some reason. I've since edited.)
Last edited by Exaskryz on 07 Jan 2017, 16:01, edited 1 time in total.
Re: Message with random probability when pressing a button
You can also use SetTimer with negative value, it will execute specyfied label after for eg 20000ms once and you do not need disable timer later (SetTimer, HideTip, Off)
Code: Select all
Tab::
Random Num, 1, 600
if (Num=1) {
MsgBox, , this is a title!,blablabla,
}
else {
ToolTip, blablablabla ; (, , , 1) <--- in this case it is not required
SetTimer, HideTip, -20000 ; milliseconds
}
return
HideTip:
Tooltip
return
Re: Message with random probability when pressing a button
Would it be hard to make all this happen not when i click a button, but when certain windows pop up?
I wouild identify the windows by their title, but theyre multiple different ones (including some of the same words).
I wouild identify the windows by their title, but theyre multiple different ones (including some of the same words).
Re: Message with random probability when pressing a button
WinWaitActive (and SetTitleMatchMode) may be what you're looking for?
Instead of manual triggering a hotkey, you'd probably want a Loop with WinWaitActive/WinWaitNotActive to alternate when the window appears and goes away.
There is WinWait as an alternative to WinWaitActive.
Instead of manual triggering a hotkey, you'd probably want a Loop with WinWaitActive/WinWaitNotActive to alternate when the window appears and goes away.
There is WinWait as an alternative to WinWaitActive.
Re: Message with random probability when pressing a button
When i use the HideTip line i get an error message "target label doesnt exist". Also i want more than 1 label to run at the same time, is that possible? Each one to dissappear after a certain time. I know that it has to do with WhichTooltip, but i dont know how to have them stack up continously.
Re: Message with random probability when pressing a button
For the label not existing, did you copy the full code of smarq8's? There is actually a bit more below the "return" - the codebox is scrollable.
You can have more than 1 label running at a time. Depending on how you're implementing the multiple tooltips, you can just have HideTip1, HideTip2, HideTip3 and change what label the SetTimer points to when it loads up that number Tooltip.
You can have more than 1 label running at a time. Depending on how you're implementing the multiple tooltips, you can just have HideTip1, HideTip2, HideTip3 and change what label the SetTimer points to when it loads up that number Tooltip.
Who is online
Users browsing this forum: Google [Bot] and 125 guests