Open Side Menu Go to the Top
Register
AutoHotkey help AutoHotkey help

06-13-2016 , 04:39 PM
Evening all,

My apologies for asking this but I'm all at sea. I'm trying to set up AHK to give me a random number next to my cursor and I have a script that seems to be trying to do that, however there are two problems.

First, the script itself seems to be faulty in some way as the number is simply not refreshing at present. Second, what I'd really like it to do is instead of refreshing after a given number of seconds, instead have it refresh on a key command (for argument's sake ctrl-q).

I've posted the script below and any help at all would be much appreciated.

SetBatchLines, -1
lastNumTick := A_TickCount
Random, randNum, 1, 100
SetTimer, UpdateRandomNumber, 1
UpdateRandomNumber:
If (ATickCount > lastNumTick+4000) {
Random, randNum, 1, 100
lastNumTick := ATickCount
}
ToolTip, %randNum%
Return
ESC::ExitApp
AutoHotkey help Quote
06-14-2016 , 12:24 AM
Take a look at hotkeys : https://autohotkey.com/docs/Hotkeys.htm

Code below a hotkey declaration will execute when the combination is pressed.

The declaration for ctrl Q would be ^q::

So just this would work:

^q::
Random, randNum, 1, 100
ToolTip, %randNum%
AutoHotkey help Quote
06-14-2016 , 03:34 AM
This is great - thanks so much for the help.
AutoHotkey help Quote
07-14-2016 , 08:06 PM
Any tips on getting this to update while hovering by cursor?

The hot key suggestion does work, however.
AutoHotkey help Quote
07-15-2016 , 11:41 PM
Quote:
Originally Posted by jdavis86
Any tips on getting this to update while hovering by cursor?
It is not clear what behaviour you want.
AutoHotkey help Quote
07-16-2016 , 01:37 AM
Quote:
Originally Posted by LoveThee
It is not clear what behaviour you want.
The script in the op has a RNG num box hovering beside cursor, that is supposed to update to a new number every few seconds.

It does not update, however.

SetBatchLines, -1
lastNumTick := A_TickCount
Random, randNum, 1, 100
SetTimer, UpdateRandomNumber, 1
UpdateRandomNumber:
If (ATickCount > lastNumTick+4000) {
Random, randNum, 1, 100
lastNumTick := ATickCount
}
ToolTip, %randNum%
Return
ESC::ExitApp
AutoHotkey help Quote
06-01-2018 , 11:59 AM
Quote:
Originally Posted by jdavis86
The script in the op has a RNG num box hovering beside cursor, that is supposed to update to a new number every few seconds.

It does not update, however.

SetBatchLines, -1
lastNumTick := A_TickCount
Random, randNum, 1, 100
SetTimer, UpdateRandomNumber, 1
UpdateRandomNumber:
If (ATickCount > lastNumTick+4000) {
Random, randNum, 1, 100
lastNumTick := ATickCount
}
ToolTip, %randNum%
Return
ESC::ExitApp
A few years later... I want this too, anyone?
AutoHotkey help Quote
06-02-2018 , 05:09 AM
A kind person helped me set it up. Here's for anyone wanting the script; A rng box hovering beside the cursor:

#Persistent
CoordMode, Mouse, Screen
CoordMode, Tooltip, Screen
SetBatchLines, -1
OnExit, exitRoutine
CallBack := RegisterCallback("MouseHook")
hook := SetWindowsHookEx(14, CallBack) ; WH_MOUSE_LL := 14
MouseGetPos, mousePosX, mousePosY
SetTimer, GetNewNumber, 5000
GetNewNumber:
Random, MyNumber , 0, 100
ShowToolTip:
ToolTip, %MyNumber%, (mousePosX + 10), (mousePosY + 10)
return
exitRoutine:
if hook
UnhookWindowsHookEx(hook)
exitapp
return
MouseHook(nCode, wParam, lParam)
{
Global mousePosX, mousePosY
Critical 1000
if nCode >= 0
{
mousePosX := NumGet(lParam+0, 0, "Int")
mousePosY := NumGet(lParam+0, 4, "Int")
settimer, ShowToolTip, -1
}
Return CallNextHookEx(nCode, wParam, lParam)
}
SetWindowsHookEx(idHook, pfn)
{
Return DllCall("SetWindowsHookEx", "int", idHook, "Ptr", pfn, "Ptr", DllCall("GetModuleHandle", "Ptr", 0, "Ptr"), "UInt", 0)
}
CallNextHookEx(nCode, wParam, lParam, hHook = 0)
{
Return DllCall("CallNextHookEx", "Ptr", hHook, "int", nCode, "Ptr", wParam, "Ptr", lParam)
}
UnhookWindowsHookEx(hHook)
{
Return DllCall("UnhookWindowsHookEx", "Ptr", hHook)
}
AutoHotkey help Quote

      
m