SendKeys and Python 2.7

Jakson A. Aquino jaksonaquino at gmail.com
Fri Sep 10 01:24:30 CEST 2010


On Thu, Sep 9, 2010 at 5:40 PM, Michel Claveau - MVP
<enleverLesX_XXmcX at xmclavxeaux.com.invalid> wrote:
> Hi!
>
> Example for send ^V  (with PyWin32):
>
>  import time,win32api,win32con
>  win32api.keybd_event(win32con.VK_CONTROL, 0, 0, 0)
>  win32api.keybd_event(ord('V'), 0, win32con.KEYEVENTF_EXTENDEDKEY | 0, 0)
>  time.sleep(0.05)
>  win32api.keybd_event(ord('V'), 0, win32con.KEYEVENTF_EXTENDEDKEY | win32con.KEYEVENTF_KEYUP, 0)
>  win32api.keybd_event(win32con.VK_CONTROL, 0, win32con.KEYEVENTF_KEYUP, 0)

Thank you very much! Your code solved my problem. I added some lines
to set the focus into R before the ^V and then back to Vim:

import time,win32api,win32con,win32com.client

shell = win32com.client.Dispatch("WScript.Shell")
shell.AppActivate("R Console")
win32api.keybd_event(win32con.VK_CONTROL, 0, 0, 0)
win32api.keybd_event(ord('V'), 0, win32con.KEYEVENTF_EXTENDEDKEY | 0, 0)
time.sleep(0.05)
win32api.keybd_event(ord('V'), 0, win32con.KEYEVENTF_EXTENDEDKEY |
win32con.KEYEVENTF_KEYUP, 0)
win32api.keybd_event(win32con.VK_CONTROL, 0, win32con.KEYEVENTF_KEYUP, 0)
shell.AppActivate("Vim")

Best regards,

Jakson Aquino



More information about the Python-list mailing list