Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic bScan values are missing in keybd_event calls (Read 558 times)
GB_Rollo
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 9
Joined: Mar 17th, 2023
bScan values are missing in keybd_event calls
Mar 17th, 2023 at 9:45am
Print Post  
Hi,

I've some trouble using the virtual keyboard on few applications that react only on bScan values sent through keybd_event methods (mainly arrows, pg up/down, home/end).
According to Microsoft documentation on keybd_event (see next message), I've temporarly fix/changed your SendKey() method to take that in count and now everything's working fine.

Can you please give us the possibility to also [b]specify the bScanCode[/b] when defining keys [b]in a custom TemplateLayout[/b] ? (it would certainly be usefull to have those things in your standard templatelayout)

Here is an extract of the modified SendKey() method (from MindFusion.UI.Wpf.NativeMethods) with "hardcoded" things.
I had to give the "KEYEVENTF_EXTENDEDKEY" flag and the right bScan value depending on the keyCode.

[code c++]
/// <summary>
/// This method send specified key to active vindow
/// </summary>
/// <param name="keyCode">byte</param>
internal static void SendKey(byte keyCode)
{
...
     switch (keyCode)
     {
           case 0x10://VK_SHIFT
...
           default:
                 byte bScan = 0;
                 var keyDownFlag = 0;

                 if (keyCode is >= 33 and <= 40)
                 {
                       bScan = GetBScanFromKeyCode(keyCode);
                       keyDownFlag = KEYEVENTF_EXTENDEDKEY;
                 }

                 keybd_event(keyCode, bScan, keyDownFlag, (UIntPtr)0);
                 keybd_event(keyCode, bScan, keyDownFlag | VK_KEYUP, (UIntPtr)0);
                 break;
     }
}

internal static byte GetBScanFromKeyCode(byte keyCode)
{
     return keyCode switch
     {
           33 => 73, //Page Up
           34 => 81, //Page Down
           35 => 79, //End
           36 => 71, //Home
           37 => 75, //Arrow Left
           38 => 72, //Arrow Up
           39 => 77, //Arrow Right
           40 => 80, //Arrow Down
           _ => 0
     };
}
[/code]

Thank you,
Guillaume
  
Back to top
 
IP Logged
 
GB_Rollo
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 9
Joined: Mar 17th, 2023
Re: bScan values are missing in keybd_event calls
Reply #1 - Mar 17th, 2023 at 9:45am
Print Post  
Microsoft documentation on keybd_event :
https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-keybd_eve
nt

Microsoft documentation on Key Scan Codes :
https://learn.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-6
.0/aa299374(v=vs.60)

I've tested the virtual keyboard, physical keyboard and OSK using this very usefull link to find and understand what was missing :
https://w3c.github.io/uievents/tools/key-event-viewer.html
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3153
Joined: Oct 19th, 2005
Re: bScan values are missing in keybd_event calls
Reply #2 - Mar 20th, 2023 at 8:46am
Print Post  
Hi,

Scan codes are supposedly hardware dependent and applications should only rely on virtual-key codes. If we want to be precise, we'd also need the scan-code set specified:

https://www.win.tue.nl/~aeb/linux/kbd/scancodes-10.html
https://en.wikipedia.org/wiki/Scancode#PC_compatibles

We'll have in mind adding a property for that to next version.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
GB_Rollo
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 9
Joined: Mar 17th, 2023
Re: bScan values are missing in keybd_event calls
Reply #3 - Mar 20th, 2023 at 1:27pm
Print Post  
Hi,

Include those changes in the next version would be great!

Thank you,
Guillaume
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint