Python ctypes keybd_event模拟ctrl + alt + delete

时间:2014-06-04 06:46:56

标签: python winapi keyboard-shortcuts ctypes

我试图用keybd_event模拟ctrl + alt + del,但它没有做任何事情,像ctrl + esc或alt + tab这样的东西可以正常工作ctrl + alt + del won&#t; t工作

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

2 个答案:

答案 0 :(得分:5)

CTRL + ALT + DEL 是一个特殊的密钥序列,称为secure attention sequence,出于安全考虑,不能使用keybd_inputSendInput伪造。

您需要使用SendSAS API调用来模拟SAS。请仔细阅读文档,确保您遵守此功能的严格要求。

答案 1 :(得分:1)

这是一种Windows安全机制。 CTRL + ALT + DEL 很特别。对于登录提示,至少有一个理由是"按 CTRL + ALT + DEL "通过按下它你确保Windows确实要求你的密码,而不仅仅是一些伪装成Windows提示的程序。