Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stdWindow.SendKeysEvent() - Await key received #63

Open
sancarn opened this issue Dec 10, 2022 · 0 comments
Open

stdWindow.SendKeysEvent() - Await key received #63

sancarn opened this issue Dec 10, 2022 · 0 comments
Labels
enhancement New feature or request lib-stdWindow

Comments

@sancarn
Copy link
Owner

sancarn commented Dec 10, 2022

Use SetWindowHookEx() to create a KeyboardHook to ensure all keys sent by keybd_event() are received.

Pseudo-code:

Function KeybdHook(key, ...)
  For iKey = 1 to len(keys)
    if not keys(iKey).received then
      if key.code = keys(iKey).code then
        key.received = true
        exit for
      end if
      exit for
    end if
  next
  KeybdHook = CallNextHookEx(...)
End Function

Function SendKeysEvent(..., Optional bWaitForRetrieval as boolean)
  if bWaitForRetrieval then iHook = SetWindowHookEx(ActiveWnd, WH_KEYBOARD, AddressOf KeybdHook)
  For iKey = 1 to len(keys)
    keybd_event(keys(iKey))
  next 
  if bWaitForRetrieval then
    While not keys(len(keys)).received
      DoEvents
    Wend
    Call ClearWindowHookEx(iHook)
  end if
  
End Function

See also:

@sancarn sancarn added enhancement New feature or request lib-stdWindow labels Oct 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request lib-stdWindow
Projects
Status: Feature Request/Unknown requirement
Development

No branches or pull requests

1 participant