SendInput and keyboard hook

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
trismarck
Posts: 506
Joined: 30 Sep 2013, 01:48
Location: Poland

SendInput and keyboard hook

Post by trismarck » 25 Oct 2013, 09:59

I don't quite understand this part of the documentation:
Documentation wrote:If a script other than the one executing SendInput has a low-level keyboard hook installed, SendInput automatically reverts to SendEvent (or SendPlay if SendMode InputThenPlay is in effect). This is done because the presence of an external hook disables all of SendInput's advantages, making it inferior to both SendPlay and SendEvent. However, since SendInput is unable to detect a low-level hook in programs other than AutoHotkey v1.0.43+, it will not revert in these cases, making it less reliable than SendPlay/Event.
Does that mean that:
  • if scriptA is currently sending keystrokes through the SendInput mechanism and scriptB:
    • has a keyboard hook installed and
    • wants to send keystrokes through SendInput _at the same time_
    then scriptB reverts to SendPlay / SendEvent _at that particular keystroke delivery_; or
  • if there is at least one AHK script that uses a keyboard hook to catch keys, then SendInput can't be used in any other AHK script; or
  • something else
Also
  1. what happens if there is a process that uses a keyboard hook, but AHK doesn't know that that process uses a keyboard hook and AHK sends keys through SendInput anyway? (in particular, how does the presence of the keyboard hook of a process affect SendInput)
  2. With SendInput, is it that only the first script that 'registers' the SendMode as SendInput is allowed to use SendInput at all? (and all scripts launched later revert to other modes)
  3. If one script sends keys to the other script, is there a way to determine, by what SendMode method were those keys sent/catched? (if they _were_ catched in the receiver script) (supposing there could be other scripts that cause the sender script to change the SendMode).

lexikos
Posts: 9665
Joined: 30 Sep 2013, 04:07
Contact:

Re: SendInput and keyboard hook

Post by lexikos » 25 Oct 2013, 20:22

if there is at least one AHK script that uses a keyboard hook to catch keys, then SendInput can't be used in any other AHK script
Basically. SendInput (or Send in SendInput mode) instead acts like SendEvent with SetKeyDelay -1, 0.

1. Keystrokes by the user can be interspersed with keystrokes send by SendInput.
2. No.
3. No.

User avatar
trismarck
Posts: 506
Joined: 30 Sep 2013, 01:48
Location: Poland

Re: SendInput and keyboard hook

Post by trismarck » 26 Oct 2013, 02:55

Thank you. So the conclusion is that, to make sure that keys are sent by SendInput reliably:
  • no AHKScript script (other than the one using SendInput) can have a keyboard hook installed
  • no _other_ program can have a keyboard hook installed
The only program that _can_ have the keyboard hook is the script that uses SendInput to send data.
Note also that:
  • if zero programs have a keyboard hook installed, then _multiple_ AHKScript scripts can use SendInput.
  • if the only program that has the keyboard hook installed is the current AHKScript, then only that _one_ script can use SendInput reliably.
  • if there is at least one program that has the keyboard hook installed and that program is not the current AHKScript script, then that AHKScript script can't use SendInput reliably.
//edit: related - Lexikos post about SendInput.

Post Reply

Return to “Ask for Help (v1)”