Keyboard layout switch on the fly in C++ using GetKeyName() function in windows

  • Thread starter Thread starter SuyashD
  • Start date Start date
S

SuyashD

Guest
I am trying to get the key-value for a particular scan-code in various languages int the following way
Layout: English United States (US keyboard) 16 - Q 17 - W 18 - E 19 - R 20 - T 21 - Y Layout: French (France Keyboard) 16 - A 17 - Z 18 - E 19 - R 20 - T 21 - Y for this, I use the following code:
#include <pch.h>
#include <iostream>
#include <windows.h>

using namespace std;
int main()
{
int scancode[6] = { 16,17,18,19,20,21};
int bufferLength = 10;
char buffer[10] ;
while (1)
{
int i = 0;
for (i = 0; i < 6 ; i++)
{
unsigned int extended = scancode & 0xffff00;
unsigned int lParam = 0;

if (extended)
{

if (extended == 0xE11D00)
{
lParam = 0x45 << 16;
}
else
{
lParam = (0x100 | (scancode & 0xff)) << 16;
}

}
else {

lParam = scancode << 16;

if (scancode == 0x45)
{
lParam |= (0x1 << 24);
}
}
GetKeyNameTextA(lParam, buffer, bufferLength);
printf("%s \n", buffer);

}

}
return 0;
}
This code gives me the localized key values but if I change the layout at <g class="gr_ gr_31 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del" data-gr-id="31" id="31">run time</g> the key values are not changed. They remain the same as before, to get the changed values I have to run it again. Can anyone suggest me a fix for it?? <g class="gr_ gr_34 gr-alert gr_gramm gr_inline_cards gr_run_anim Punctuation only-ins replaceWithoutSep" data-gr-id="34" id="34">Also</g> suggest if there is an alternative way to achieve this<g class="gr_ gr_35 gr-alert gr_gramm gr_inline_cards gr_run_anim Punctuation multiReplace" data-gr-id="35" id="35">..</g>

Continue reading...
 
Back
Top