Making a AZERTY converter and ran into problem

I am making a program that converts qwerty keyboard into a azerty keyboard. How it works is when you press q the program presses backspace then releases q then presses a. Where im running into trouble is when i try to make it so q replaces a and a replaces q. What happens is when i press q the program presses a and the when the program presses a it replaces it with q so it doesn't work. Can you tell me how to tell the difference between a physical keystroke and a keystroke made by a program. This is my code.

#include <windows.h>
#include <iostream>
SHORT WINAPI GetAsyncKeyState(
__in int vKey
);
VOID WINAPI keybd_event(
__in BYTE bVk,
__in BYTE bScan,
__in DWORD dwFlags,
__in ULONG_PTR dwExtraInfo
);

int main()
{
int a=0x41,b=0x42,c=0x43,d=0x44,e=0x45,f=0x46,g=0x47,h=0x48,i=0x49,j=0x4A,k=0x4b,l=0x4c,m=0x4d,n=0x4e,o=0x4f,p=0x50,q=0x51,r=0x52,s=0x53,t=0x54,u=0x55,v=0x56,w=0x57,x=0x58,y=0x59,z=0x5a;


while (1==1){


if (GetAsyncKeyState(q)!=0)//check if w is pressed

{keybd_event( 0x08,//backspace
0x45,
KEYEVENTF_EXTENDEDKEY | 0,
0 );




keybd_event( a,//presses a
0x45,
KEYEVENTF_EXTENDEDKEY,
0);




keybd_event( q,//releases q
0x45,
KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,
0);
}


if (GetAsyncKeyState(a)!=0)//check if w is pressed

{keybd_event( 0x08,//backspace
0x45,
KEYEVENTF_EXTENDEDKEY | 0,
0 );




keybd_event( q,//presses a
0x45,
KEYEVENTF_EXTENDEDKEY,
0);




keybd_event( a,//releases q
0x45,
KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,
0);
}




}

}



Topic archived. No new replies allowed.