【发布时间】:2012-05-08 17:08:46
【问题描述】:
我正在尝试让 SendKeysCtypes 在 py2.7 和 win7 64bit 上工作。 Here is src
问题:
运行SendKeysCtypes.py,没有任何反应。测试应该打开记事本并写一些文本。
问题代码是这样的:
def GetInput(self):
"Build the INPUT structure for the action"
actions = 1
# if both up and down
if self.up and self.down:
actions = 2
inputs = (INPUT * actions)()
vk, scan, flags = self._get_key_info()
for inp in inputs:
inp.type = INPUT_KEYBOARD
inp._.ki.wVk = vk
inp._.ki.wScan = scan
inp._.ki.dwFlags |= flags
# if we are releasing - then let it up
if self.up:
inputs[-1]._.ki.dwFlags |= KEYEVENTF_KEYUP
return inputs
def Run(self):
"Execute the action"
inputs = self.GetInput()
return SendInput(
len(inputs),
ctypes.byref(inputs),
ctypes.sizeof(INPUT))
上面代码中的SendInput() 什么都不做。
其他测试
我尝试了this answer 中的代码,它工作正常。但是这段代码 还有一些其他问题。
SendInput() returns '0' ,意思是“被另一个人阻止了 线程”
对 ctypes.GetLastError() 的调用给了我们error code 87,这意味着“ERROR_INVALID_PARAMETER”
在这里我们被卡住了,因为我的 Windows 编程非常有限,有人能解释一下吗?
编辑 1:
- 按照“64 位问题”跟踪,将我带到这个SO question,看看我是否可以转换它。
【问题讨论】:
标签: python windows 64-bit pywin32 sendkeys