简体   繁体   中英

sendkeys() to bloomberg panel python

I try to do a basic sendkeys() to and open an logged into bloomberg panel.

I am able to verify that sendkeys() works with this:

import time
import win32com.client as comclt

wsh= comclt.Dispatch("WScript.Shell")
wsh.AppActivate("Notepad") # select another application
time.sleep(0.5) # wait for half a second
wsh.SendKeys("a") # send the keys you want
print('key is sent')

What i have tried: With the above i try to change Notepad for Bloomberg or Bloomberg App Host as is seen in the task manager, but i am unable to sendkeys...

How can one get this to work or is there an alternative method that does work?

assuming you are trying to log into bloomberg automatically using some script. i use vbscript to achieve this at a scheduled time of the day.

below is my vb script saved as a.vbs file and executed using windows task manager

you will need to change loginname and password to match yours

the commented part of the loop waits for the Bloomberg chat window to appear. this was then commented as i made some settings on bloomberg to not to open chat window upon logon. - i do not remember what was exactly done then

This will work only if you have a bloomberg open terminal which does not ask for an otp after login as it generally asks on a Bloomberg Anywhere terminal

also before running this script ensure that bloomberg application is closed / not open

you may use taskkill command to close all the instances of wintrv.exe

taskkill /IM wintrv.exe /F

Below is the vbs script.

set WshShell = WScript.CreateObject("WScript.Shell") 
dim ret
ret = False
do while ret=False
ret = WshShell.AppActivate("BLOOMBERG: Login")
WScript.Sleep 10000
If ret = True Then
    'CreateObject("WScript.Shell").PopUp "here", 5
    'WshShell.AppActivate("BLOOMBERG: Login")
    WScript.Sleep 3000 
    WshShell.SendKeys "{esc}" 
    WScript.Sleep 1000 
    WshShell.SendKeys "login~" 
    WScript.Sleep 10000 
    WshShell.SendKeys "loginname{tab}password~"
    wScript.Sleep 20000
else
    Call WshShell.Run("C:\blp\Wintrv\wintrv.exe")
    WScript.Sleep 15000
End If 
loop
'WScript.Sleep 5000
'ret=False
'do while ret=False
'ret = WshShell.AppActivate("IB - IB Manager")
'if ret=False Then
'   WScript.Sleep 3000
'End If
'loop
WScript.Sleep 5000
WshShell.AppActivate("New Tab")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM