0

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 ?

D.L
  • 4,339
  • 5
  • 22
  • 45
  • The lower-level way to send keystrokes to applications is to use the Win32 API calls. Start with FindWindow() to locate the application main window, then SetForeground() to bring it to the front and get the input focus. Then use SendInput() to simulate keystrokes or mouse clicks/movement. – DS_London Jun 17 '22 at 22:21
  • I am looking at a couple of video's of how to implement `FindWindow()`, is there a recommended place for this ? – D.L Jun 20 '22 at 09:23
  • eg here: https://stackoverflow.com/questions/1823762/sendkeys-for-python-3-1-on-windows/2004267#2004267 You will need to know the window class of the window you are looking for. MS Spy++ can be used for this. – DS_London Jun 20 '22 at 10:31

1 Answers1

0

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")
Kiran Jain
  • 171
  • 1
  • 14