#InstallKeybdHook if ( WaitForAnyKey( 10000 ) ) MsgBox, <any key> pressed else MsgBox, [WaitForAnyKey] timeout expired ExitApp WaitForAnyKey( p_timeout ) { start := A_TickCount loop, { if ( idle > A_TimeIdlePhysical ) return, true else if ( A_TickCount-start >= p_timeout ) return, false idle := A_TimeIdlePhysical Sleep, 10 } }
WaitForAnyKey
Started by
shimanov
, Jan 15 2006 02:44 AM
14 replies to this topic
Self-explanatory.
#1
-
Posted 15 January 2006 - 02:44 AM
Creative use of A_TimeIdlePhysical. I'm going to try to remember to refer people to this topic when they ask about "wait for any key" (though I'm not sure the question comes up quite often enough to go into the FAQ).
#2
-
Posted 15 January 2006 - 02:54 AM
Creative use of A_TimeIdlePhysical
Thanks.
I thought, there sits a variable idle and what with it to do?
Some time passed and I waited patiently. Until I realized, that WaitForAnyKey was ripe.
Then there it was, and here it is.
#3
-
Posted 15 January 2006 - 03:17 AM
where is the key "any" ?
sorry shimanov (russian?) , very nice...
sorry shimanov (russian?) , very nice...
#4
-
Posted 15 January 2006 - 09:22 AM
where is the key "any" ?
Funny. Maybe it should be
one, some, every, or all without specification key.But any key by any other name is still a key.
#5
-
Posted 15 January 2006 - 09:40 AM
mm.. doesnt register mouse events, nor its movments or mouse clicks.,, so,, i could be using the computer with the mouse and it wouldnt notice..
wonder if that is a bug..
any ways, this is a Sub that i use if i want to wait witht the thread untill the mouse is moved ( i use to get out of a home made screensaver) :
perhaps we should merge them. :wink:
[EDIT] :!:
Solved:
Screw my script, Just add :
#InstallMouseHook
to the autoexecution bit and it will do it for the mouse as well.
wonder if that is a bug..
any ways, this is a Sub that i use if i want to wait witht the thread untill the mouse is moved ( i use to get out of a home made screensaver) :
Wait4MouseMovement: MouseGetPos,pos1,pos2 last1 = %pos1% last2 = %pos2% loop { GetKeyState, RBS, RButton, P ; rbs= Right button state GetKeystate, MBS, MButton, p ; Middle... GetKeystate, LBS, LButton, p ; Left... GetKeystate, X1BS, XButton1, p ; my 4th mouse button GetKeystate, X2BS, XButton2, p ; mt 5th button. ButtonState = %RBS%%MBS%%LBS%%X1BS%%X2BS% ;Puts all states in one if ButtonState <> UUUUU ; "<>" means "If not" , so if they are not all up. Break MouseGetPos,pos1,pos2 if pos1 <> %last1% break if pos2 <> %last2% break } Return
perhaps we should merge them. :wink:
[EDIT] :!:
Solved:
Screw my script, Just add :
#InstallMouseHook
to the autoexecution bit and it will do it for the mouse as well.
#6
-
Posted 15 January 2006 - 10:36 AM
::
I Have Spoken
::
I Have Spoken
::
Something like this:?
if ( Wait4MouseAction( 10000 ) ) MsgBox, <any mouse action> detected else MsgBox, [Wait4MouseAction] timeout expired ExitApp Wait4MouseAction(p_timeout ) { start := A_TickCount MouseGetPos,last1,last2 Loop { GetKeyState, RBS, RButton, P GetKeystate, MBS, MButton, p GetKeystate, LBS, LButton, p GetKeystate, X1BS, XButton1, p GetKeystate, X2BS, XButton2, p BtnState = %RBS%%MBS%%LBS%%X1BS%%X2BS% MouseGetPos,pos1,pos2 if ( BtnState <> "UUUUU" Or pos1 <> last1 OR pos2 <> last2) return, true if ( A_TickCount-start >= p_timeout ) return, false Sleep, 10 } }*not tested* Just LEO code tweaked and adjusted to shimanovs code.
#7
-
Posted 15 January 2006 - 10:47 AM
Ciao
toralf
I use the latest AHK version (1.1.15+)
Please ask questions in forum on ahkscript.org. Why?
For online reference please use these Docs.
toralf
I use the latest AHK version (1.1.15+)
Please ask questions in forum on ahkscript.org. Why?
For online reference please use these Docs.
If so, disregard my post.Screw my script, Just add :
#InstallMouseHook
to the autoexecution bit and it will do it for the mouse as well.
#8
-
Posted 15 January 2006 - 10:51 AM
Ciao
toralf
I use the latest AHK version (1.1.15+)
Please ask questions in forum on ahkscript.org. Why?
For online reference please use these Docs.
toralf
I use the latest AHK version (1.1.15+)
Please ask questions in forum on ahkscript.org. Why?
For online reference please use these Docs.
doesnt register mouse events...
#InstallMouseHook
You found the solution. But, technically, it is WaitForAnyKey.
I have heard of those who would type with mouse buttons and gestures -- weird stuff.
#9
-
Posted 15 January 2006 - 10:43 PM
Hi,
is there a way to temporary disable the mousehook or to ignore mouse-movements?
is there a way to temporary disable the mousehook or to ignore mouse-movements?
#10
-
Posted 30 August 2006 - 01:39 PM
Tekl
The mouse hook can be dynamically deactivated by:
1) Avoiding #InstallMouseHook.
2) Specifying #Hotstring NoMouse (if your script contains hotstrings). Or dynamically disabling all hotstrings via the Suspend command.
3) Dynamically disabling all mouse hotkeys. In other words, the mouse hook is activated only when the program determines that something in the script (usually hotkeys) requires it. If nothing requires it, the hook is deactivated.
1) Avoiding #InstallMouseHook.
2) Specifying #Hotstring NoMouse (if your script contains hotstrings). Or dynamically disabling all hotstrings via the Suspend command.
3) Dynamically disabling all mouse hotkeys. In other words, the mouse hook is activated only when the program determines that something in the script (usually hotkeys) requires it. If nothing requires it, the hook is deactivated.
#11
-
Posted 30 August 2006 - 03:19 PM
Is there a way to disregard certain keys?
Say I want my script to stop, when any key other than, say a defined hotkey is pressed. How would I define that?
Say I want my script to stop, when any key other than, say a defined hotkey is pressed. How would I define that?
#12
-
Posted 19 January 2007 - 06:35 PM
Please, could help me how can I do: Press key B and then WaitForAnyKey?
When I try this:
When I press B, WaitForAnyKey return true without waiting for next key?
When I try this:
$b:: if (WaitForAnyKey(10000)) { ... } return
When I press B, WaitForAnyKey return true without waiting for next key?
#13
-
Posted 07 December 2007 - 05:17 PM
because it starts waiting before you release the b key. the action of releasing the b key counts enough for this code as a key action.. you could add a short sleep to allow for you to release the button, or you can use keywait to wait until you release the button.
#14
-
Posted 07 December 2007 - 08:23 PM
It seems to me that this function takes advantage of an undocumented feature: A_TimeIdlePhysical can be made to ignore physical input of one type or the other by installing only one hook. In talking with Chris, it would be considered a bug since both A_TimeIdle and A_TimeIdlePhysical are intended to always capture both types of physical input (keyboard and mouse); however, I think it's a great feature and should simply be added to the documentation.
The script seems to have worked as advertised for everyone else in this thread (three years ago) and it works the same for me:
1. Installing only the keyboard hook ignores physical input from the mouse.
2. Installing only the mouse hook ignores physical input from the keyboard.
3. Installing both hooks or installing neither captures all input.
4. Using A_TimeIdle instead of A_TimeIdlePhysical captures all input regardless of the hooks installed.
Anyone care to try?
EDIT: The documentation has been updated.
The script seems to have worked as advertised for everyone else in this thread (three years ago) and it works the same for me:
1. Installing only the keyboard hook ignores physical input from the mouse.
2. Installing only the mouse hook ignores physical input from the keyboard.
3. Installing both hooks or installing neither captures all input.
4. Using A_TimeIdle instead of A_TimeIdlePhysical captures all input regardless of the hooks installed.
Anyone care to try?
;#InstallMouseHook #InstallKeybdHook While A_TimeIdlePhysical > 10 continue MsgBox, A_TimeIdlePhysical has been reset. ExitApp
EDIT: The documentation has been updated.
#15
-
Posted 01 June 2009 - 08:28 PM