joyfullservice / msaccess-vcs-addin

Synchronize your Access Forms, Macros, Modules, Queries, Reports, and more with a version control system.
Other
203 stars 40 forks source link

ShiftOpenDatabase does not seem to be reliable #390

Closed bclothier closed 1 year ago

bclothier commented 1 year ago

I'm testing the addin and I am finding that the ShiftOpenDatabase is not reliable.

There is the following comment:

https://github.com/joyfullservice/msaccess-vcs-integration/blob/88efd2ce5a6b6f60f5988f1d8c29124ff33a1a9c/Version%20Control.accda.src/modules/modLibReference.bas#L13-L18

However, if I look at Win32 API documentations for keybd_event, there is a note:

Note This function has been superseded. Use SendInput instead.

The SendInput is as far as I can tell similar semantically to VBA's SendKeys.

In contrast, the documentation for SetKeyboardState has no such notes. More importantly, we have this following remarks:

Because the SetKeyboardState function alters the input state of the calling thread and not the global input state of the system, an application cannot use SetKeyboardState to set the NUM LOCK, CAPS LOCK, or SCROLL LOCK (or the Japanese KANA) indicator lights on the keyboard. These can be set or cleared using SendInput to simulate keystrokes.

I believe the issue with both keybd_event and SendInput is the same as the VBA's SendKeys -- they are at mercy at whatever window has the keyboard focus and that will be very painful to correctly handle. I use a variant of this code which appears to be reliable on several OSes, including Windows 11.

Is there any reason why we shouldn't be using the SetKeyboardState?

joyfullservice commented 1 year ago

Yes, I have had issues with this not working very reliably as well. If the SetKeyboardState call is working well for you, including on various OSes, I am all for updating the code base to use this approach. 👍

bclothier commented 1 year ago

This was supposed to be closed by PR #388 but didn't close automatically for some reason, so closing it.

joyfullservice commented 1 year ago

This was supposed to be closed by PR #388 but didn't close automatically for some reason, so closing it.

If I recall correctly, I think the auto-close only happens when it is merged into the master (primary) branch. So it would happen eventually, but probably not for a while... 😄