come generare combinazione di tasti in Win32 API?
-
24-10-2019 - |
Domanda
ho questo codice che simula la pressione del tasto finestra. Ma come potrei farlo alla stampa finestra + d chiave, mostrando essenzialmente desktop.
void ShowDesktop(void)
{
// Simulate a key press
keybd_event( VK_LWIN,
0x5B,
KEYEVENTF_EXTENDEDKEY | 0,
0 );
// Simulate a key release
keybd_event( VK_LWIN,
0x5B,
KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,
0);
}
Soluzione
keybd_event
funzione con il valore della chiave virtuale e il codice di scansione hardware per il D per ottenere questo valore è possibile utilizzare il MapVirtualKey
funzione.
provare questo esempio.
//simulate the Win key press
keybd_event(VK_LWIN, 0x5B, 0, 0);
//simulate the 'D' key press,the 0x44 is the Virtual key value for the 'D' key, the 0x20 vaue is the hardware scan code for the 'D' key
keybd_event(0x44, 0x20, 0, 0);
//simulate the 'D' key release
keybd_event(0x44, 0x20, KEYEVENTF_KEYUP, 0);
//simulate the Win key release
keybd_event(VK_LWIN, 0x5B, KEYEVENTF_KEYUP, 0);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow