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 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;
}

his code gives me the localized key values but if I change the layout at run time 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_21 gr-alert gr_gramm gr_inline_cards gr_run_anim Punctuation only-ins replaceWithoutSep" data-gr-id="21" id="21">Also</g> suggest if there is an alternative way to <g class="gr_ gr_19 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="19" id="19">acheive</g> this<g class="gr_ gr_22 gr-alert gr_gramm gr_inline_cards gr_run_anim Punctuation multiReplace" data-gr-id="22" id="22">..</g>

Continue reading...
 
Back
Top