如何使用 shell.SendKeys 选择并删除所有内容(ctrl + shift + left arrow + del)?

发布于 2024-09-13 02:45:26 字数 442 浏览 3 评论 0原文

嘿,我在这里遇到了一些麻烦...

如何使用 sendkeys 从字段中删除整个文本?

如何发送按住 ctrl+shift 并按向左箭头并在之后删除键?

编辑:

例如,我有这部分代码

ctypes.windll.user32.SetCursorPos(910,475)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0)
time.sleep(0.1)
shell.SendKeys(inf_firstname)

这部分选择一个字段并粘贴名字信息(就像宏一样),但我想在粘贴删除字段内容的信息之前执行一些操作(如果有)一个……

卡佩切?

Hey, I'm having some trouble here...

How can I delete an entire text from a field with the sendkeys ?

How can I send the ctrl+shift pressed with the left arrow and delete key after?

edit:

for example, I have this part of the code

ctypes.windll.user32.SetCursorPos(910,475)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0)
time.sleep(0.1)
shell.SendKeys(inf_firstname)

This part select a field and paste the firstname information (just like a macro), but I want to do something before paste the information that deletes the content of the field, if it has one...

capiche?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

莳間冲淡了誓言ζ 2024-09-20 02:45:26

我不知道 Sendkeys,但我知道你可以使用 ctypes 发送击键。

以下是如何通过发送 CTRL+A 和 BACK 来删除文本:

ctypes.windll.user32.keybd_event(0x11, 0, 0, 0) #CTRL is down
ctypes.windll.user32.keybd_event(ord("A"), 0, 0, 0) #A is down
ctypes.windll.user32.keybd_event(ord("A"), 0, 0x0002, 0) #A is up
ctypes.windll.user32.keybd_event(0x11, 0, 0x0002, 0) #CTRL is up
ctypes.windll.user32.keybd_event(0x08, 0, 0, 0) #BACK is down
ctypes.windll.user32.keybd_event(0x08, 0, 0x0002, 0) #BACK is up

您需要发送 Windows 虚拟键代码。有关完整列表,请参阅此处

它可能与 SendKeys 类似

我希望它有帮助

I don't know with Sendkeys but I know that you can send keystrokes with ctypes.

Here is how to remove a text by sending CTRL+A and BACK:

ctypes.windll.user32.keybd_event(0x11, 0, 0, 0) #CTRL is down
ctypes.windll.user32.keybd_event(ord("A"), 0, 0, 0) #A is down
ctypes.windll.user32.keybd_event(ord("A"), 0, 0x0002, 0) #A is up
ctypes.windll.user32.keybd_event(0x11, 0, 0x0002, 0) #CTRL is up
ctypes.windll.user32.keybd_event(0x08, 0, 0, 0) #BACK is down
ctypes.windll.user32.keybd_event(0x08, 0, 0x0002, 0) #BACK is up

You need to send the windows virtual key code. See here for the full list.

It may be similar with SendKeys

I hope it helps

開玄 2024-09-20 02:45:26

可能想用 Ctrl+A 代替?
您能给出一个不适合您的代码的简短示例吗?

根据 SendKeys 的实现,它可能不会一次接受所有这些。它可能需要多次 SendKeys 调用。您可以尝试在单独的 SendKeys 调用中一次执行一项操作。

编辑:

http://msdn.microsoft.com /en-us/library/8c6yea83.aspx

在我看来你应该能够做到这一点:

shell.SendKeys("^a")
shell.SendKeys("{DELETE}")

Might want to do Ctrl+A instead?
Can you give a short example of the code that isn't working for you?

Depending on the implementation of SendKeys, it might not accept all those at once. It might require multiple SendKeys invocations. You could try doing one at a time, in separate calls to SendKeys.

Edit:

http://msdn.microsoft.com/en-us/library/8c6yea83.aspx

It seems to me you should be able to do this:

shell.SendKeys("^a")
shell.SendKeys("{DELETE}")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文