Posts: 15
Threads: 2
Joined: Aug 2022
Reputation:
0
Hi. We've been looking for a way to catch pressed keys from the browser however, we can't find a way to do this without javascript.
We did find an undocumented function called browser_OnKeyPress(Key as Integer) but this one doesn't seem to work at all. No matter how many times we press a key, it doesn't get activated.
Is there a way to catch or redirect a keypress first to VBA/Access without javascript?
We're using the activex version.
Thanks in advance.
Posts: 384
Threads: 57
Joined: Oct 2016
Reputation:
12
Hi,
Yes and no.
Officially Microsoft does not support to catch key events, however they have exposed a way to catch short cut keys.
This is exposed in the next release of AntView via the AntViewPhysicalKeyStatus interface.
I will email you a link to the private version so that you can take a look.
--
Wil
Posts: 15
Threads: 2
Joined: Aug 2022
Reputation:
0
Thank for the new version. I've tried it but it seems like it's not supported in VBA. When i want to implement it, it says that the function or interface is marked as reserved or is not supported by Visual Basic.
See: https://learn.microsoft.com/nl-nl/office...6rd%3Dtrue
Posts: 384
Threads: 57
Joined: Oct 2016
Reputation:
12
2022-12-29, 18:43:07
(This post was last modified: 2022-12-29, 19:51:01 by wila.)
Hi,
I just verified in the code of the AntView control and the interface in the control is marked as public and AFAICT should be accessible by MS Access.
For MS Excel I remember that it creates small cache files of an ActiveX control (.exd files) when you first use it in MS Excel.
When you upgrade an ActiveX you have to get rid of those old caching files in order to use the new functionality the control might expose. I even adjusted the installer to get rid of those caching files -- when you're using MS Excel.
See https://doc.antview.dev/hs95.htm
Could it be that MS Access has a similar mechanism?
--
Wil
text was edited to be more clear.
Posts: 15
Threads: 2
Joined: Aug 2022
Reputation:
0
Hello Wila,
The functionality is visible, but when i click on it it just shows an error message that its marked as restricted or that the automation type is not supported. Same goes for Excel.
Access does not have such temp file. I've also tried creating a new Access app, reinstalling and registering the files manually with no success. The function/method is available, but it can't be implemented.
Just to be sure, we're both talking about the "OnAccelatorKeyPressed"-function right?
Posts: 384
Threads: 57
Joined: Oct 2016
Reputation:
12
(2023-01-02, 08:21:44)hsacrm Wrote: Hello Wila,
The functionality is visible, but when i click on it it just shows an error message that its marked as restricted or that the automation type is not supported. Same goes for Excel.
Access does not have such temp file. I've also tried creating a new Access app, reinstalling and registering the files manually with no success. The function/method is available, but it can't be implemented.
Just to be sure, we're both talking about the "OnAccelatorKeyPressed"-function right?
Hi,
Yes, we're both talking about the new OnAcceleratorKeyPressed event.
Thanks for the clarification, let me see if I can reproduce your issue and figure out what is going on.
This was implemented based on your question here: https://forums.antwise.com/showthread.ph...408#pid408
so it would be sad if you are the one who then can not use it.
FWIW, it does work OK in other environments, apparently something is different in MS Access.
I will report back once I get a chance to look into this.
--
Wil
Posts: 384
Threads: 57
Joined: Oct 2016
Reputation:
12
(2023-01-02, 11:50:42)wila Wrote: I will report back once I get a chance to look into this.
Ok, I was able to reproduce this issue.
Interesting..
Turns out that MS Access does not like data type unsigned long for the VirtualKey parameter.
It's a bit ironical as parameter KeyEventLParam is a long.
Also seeing this same issue in the AntViewPhysicalKeyStatus interface for params RepeatCount and Scancode.
Hmm.. I guess we can drop back to a long data type on these parameters.
It is not perfect, but what is perfect these days?
I'm really glad we found this before the next official release.
You will be getting an email with a new private build to test from me in a bit.
--
Wil
Posts: 15
Threads: 2
Joined: Aug 2022
Reputation:
0
Yes, it works! Thank you very much.
I've played a bit around with it. The behaviour is somewhat different than what i expected.
Am i correct when saying that the keyaccelator only work when pressing a key modifier? (Ctrl, alt etc)
The way it activates may bring some difficulties, to catch ctrl + s for example. The function gets called allot of times when holding down the ctrl-key (which even lead to a crash once).
We can reduce it by checking if the key is released. It will then get called twice. Once for the ctrl-key and once for the S-key. So i think we have to build something to wait till the key get released and check what was pressed in the meantime.
We have to play around it a bit more to fully grasp it, but we're getting there!
Posts: 384
Threads: 57
Joined: Oct 2016
Reputation:
12
(2023-01-02, 14:29:06)hsacrm Wrote: Yes, it works! Thank you very much.
I've played a bit around with it. The behaviour is somewhat different than what i expected.
Am i correct when saying that the keyaccelator only work when pressing a key modifier? (Ctrl, alt etc)
The way it activates may bring some difficulties, to catch ctrl + s for example. The function gets called allot of times when holding down the ctrl-key (which even lead to a crash once).
We can reduce it by checking if the key is released. It will then get called twice. Once for the ctrl-key and once for the S-key. So i think we have to build something to wait till the key get released and check what was pressed in the meantime.
We have to play around it a bit more to fully grasp it, but we're getting there!
Glad to hear that you got it to work.
Yes, this interface only works for accelerator keys.
So shortcut keys with modifier keys like you say, but it also supports some special keys like Escape and function keys.
Yes, it is different from what you expect.
The reason for that is as I explained earlier here [ 1], let me quote.
The problem is that the WebView2 control is Out-Of-Process and has an In-Process front end.
So while you're typing in the -out of process- control, the -in process- front end doesn't get any of those events.
It would be good if MS adds a proper interface for keyboard events.
But at least you can catch short cut keys now without having to do this at the javascript layer.
--
Wil
Posts: 15
Threads: 2
Joined: Aug 2022
Reputation:
0
I've continued to coding around the keyevent, and it seems to work. However, one small problem is that we can't know whether the shift-key is pressed.
For example, when pressing ctrl + shift, we only get that ctrl is pressed. With ctrl + shift + g, only ctrl and g.
When i read the microsoft website it says that is should be possible with scancodes: https://learn.microsoft.com/en-us/window...sage-flags
Is there a way to return whether the shift-key is pressed as well?
Posts: 384
Threads: 57
Joined: Oct 2016
Reputation:
12
Hi,
The PhysicalKeyStatus parameter of type AntViewPhysicalKeyStatus returns a scancode as one of its properties.
Have you tried to get the info via that already?
--
Wil
Posts: 15
Threads: 2
Joined: Aug 2022
Reputation:
0
yes, but it doesn't return a different value when pressing the shift-key.
Posts: 384
Threads: 57
Joined: Oct 2016
Reputation:
12
You are quite right.
The data is passed as is and is what MS gives me, so the scancode is what it is.
I don't think it is a good idea if AntView changes the actual scancodes.
However, not all is lost.
Was just looking at the test code and down here, we also bumped into the same issue.
You can get the status of the modifier keys via the GetKeyState windows API call.
The nVirtKey parameter for GetKeyState is $10 for VK_SHIFT and $11 for VK_CONTROL
So not too hard to get the state of the modifier keys if you're able to access the Windows API.
--
Wil
Posts: 384
Threads: 57
Joined: Oct 2016
Reputation:
12
Hi,
Nevermind the GetKeyState API call.
You won't be the only one who bumps into this and as this feature is not yet public, it was super easy to quickly add the functionality.
The AntViewPhysicalKeyStatus interface now also has IsControlKeyDown and IsShiftKeyDown properties.
So that would be the easiest way for you.
I will be sending out a new private build later today.
--
Wil
Posts: 15
Threads: 2
Joined: Aug 2022
Reputation:
0
Hello Wil,
I've tried the latest build. It works perfectly fine. Thanks.
These aren't issues for me anymore, just wanted to tell my observation if anyone has the same problems in the future:
- As long as you press down a key, the event will be called an endless time. So make sure your code is compatible with this.
- IsShiftKeyDown and IsControlKeyDown will always return 0 if you release it.
This means you cannot do a check like `if keyreleased then` because you won't know anymore if the accelatorkeys were pressed. So when pressing or holding down ctrl + shift + x, IsControlKeyDown and IsShiftKeyDown will return 1. Releasing it will show 0 even if you check whether the x-key was pressed on release.
- You cannot debug manually in VBA, the code will simply stop executing at a breakpoint as if it's never called. Debug by using print-statements. It probably has something to do with that the browser is async.
Posts: 384
Threads: 57
Joined: Oct 2016
Reputation:
12
(2023-01-05, 11:00:10)hsacrm Wrote: Hello Wil,
I've tried the latest build. It works perfectly fine. Thanks.
These aren't issues for me anymore, just wanted to tell my observation if anyone has the same problems in the future:
- As long as you press down a key, the event will be called an endless time. So make sure your code is compatible with this.
- IsShiftKeyDown and IsControlKeyDown will always return 0 if you release it.
This means you cannot do a check like `if keyreleased then` because you won't know anymore if the accelatorkeys were pressed. So when pressing or holding down ctrl + shift + x, IsControlKeyDown and IsShiftKeyDown will return 1. Releasing it will show 0 even if you check whether the x-key was pressed on release.
- You cannot debug manually in VBA, the code will simply stop executing at a breakpoint as if it's never called. Debug by using print-statements. It probably has something to do with that the browser is async.
Glad to hear it works for you.
The code was tested on key-up, not key down. Even on key-up the shift and control modifiers still showed as "down".
For IsShiftKeyDown and IsControlKeyDown I figured to use a similar interface as WebView2's CoreWebView2PhysicalKeyStatus interface. So the return data type is integer and it returns 1 instead of using booleans.
One difference though is that -since I'm using the GetKeyState API- is that the function IsShiftKeyDown/IsControlKeyDown test the moment you query them.
This means that if you would run in a debug session and set a breakpoint that the status of these keys are showing the key status from your debug session. Not the status from before the breakpoint triggers.
Perhaps this can be handled, but certainly not now as I'm very close to a release and don't want to risk breaking things.
I have updated the documentation to mention that tidbit as it is an important difference.
--
Wil
Posts: 15
Threads: 2
Joined: Aug 2022
Reputation:
0
2023-01-05, 12:50:00
(This post was last modified: 2023-01-05, 12:50:23 by hsacrm.)
(2023-01-05, 11:39:41)wila Wrote: ..
The code was tested on key-up, not key down. Even on key-up the shift and control modifiers still showed as "down".
..
Are you sure you meant keyup? Maybe the browser returns them in a reversed order, because here are my results by pressing only the ctrl-key:
On down:
keyevent 0
virtualkey 17
KeyEventLParam 1900545
KeyEventKind 0
IsExtendedKey 0
IsKeyReleased 0
IsMenuKeyDown 0
RepeatCount 1
ScanCode 29
WasKeyDown 0
IsShiftKeyDown 0
IsControlKeyDown 1
On release:
keyevent 1
virtualkey 17
KeyEventLParam -1071841279
KeyEventKind 1
IsExtendedKey 0
IsKeyReleased 1
IsMenuKeyDown 0
RepeatCount 1
ScanCode 29
WasKeyDown 1
IsShiftKeyDown 0
IsControlKeyDown 0
Posts: 384
Threads: 57
Joined: Oct 2016
Reputation:
12
Hi,
Yes.. and I understand what the difference is.. I tested with Ctrl+T and on releasing the "T" it still shows the Ctrl+Key as down.. which makes sense
Either way.. it works.
--
Wil
Posts: 15
Threads: 2
Joined: Aug 2022
Reputation:
0
Ah yes, you're quite right. I was releasing both keys at the same time, that's why it didn't show as pressed.
|