Shay
Shay

Reputation: 1405

Python ctypes keybd_event simulate ctrl+alt+delete

I'm trying to simulate ctrl+alt+del with keybd_event but it doesn't do anything, stuff like ctrl+esc or alt+tab do work yet ctrl+alt+del won't work.

import ctypes
ctypes.windll.user32.keybd_event(0x11, 0, 0, 0) #CTRL is down
ctypes.windll.user32.keybd_event(0x12, 0, 0, 0) #ALT is down
ctypes.windll.user32.keybd_event(0x2E, 0, 0, 0) #DEL is down
ctypes.windll.user32.keybd_event(0x2E, 0, 0x0002, 0) #DEL is up
ctypes.windll.user32.keybd_event(0x12, 0, 0x0002, 0) #ALT is up
ctypes.windll.user32.keybd_event(0x11, 0, 0x0002, 0) #CTRL is up

Upvotes: 3

Views: 2930

Answers (2)

otus
otus

Reputation: 5732

That's a Windows security mechanism. CTRL + ALT + DEL is special. At least one justification is the "Press CTRL + ALT + DEL for login prompt" thing where by pressing it you make sure Windows is really asking for your password and not just some program masquerading as a Windows prompt.

Upvotes: 1

David Heffernan
David Heffernan

Reputation: 613511

CTRL + ALT + DEL is a special key sequence, known as the secure attention sequence that, for security reasons, cannot be faked using keybd_input or SendInput.

You will need to use the SendSAS API call to simulate the SAS. Do read the documentation carefully do make sure that you adhere to the stringent requirements of this function.

Upvotes: 5

Related Questions