Pergunta

My current code is:

[DllImport("user32.dll", SetLastError = true)] 
static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);  

public const int KEYEVENTF_EXTENDEDKEY = 0x0001; //Key down flag 
public const int KEYEVENTF_KEYUP = 0x0002; //Key up flag 
public const int VK_RMENU = 0xA5;

keybd_event(VK_SHIFT, 0, KEYEVENTF_EXTENDEDKEY, 0);
keybd_event(VK_Q, 0, KEYEVENTF_EXTENDEDKEY, 0);
keybd_event(VK_Q, 0, KEYEVENTF_KEYUP, 0);
keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);

I get the capital Q as needed, but the problem is, the "Shift" sticks.

All letter after that are all capital. the only way to get lowercase is to change to caps lock. How can i solve this problem?

Thanks in advance

Foi útil?

Solução

I believe Cody Gray gave you the resolution for your issue. Just replace your P/Invoke calls with:

keybd_event(VK_SHIFT, 0, 0, 0);
keybd_event(VK_Q, 0, 0, 0);
keybd_event(VK_Q, 0, KEYEVENTF_KEYUP, 0);
keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top