Jump to content

Recommended Posts

 

Hi all I have built some code for my day trading station. I have 6 identical order entry windows on one monitor. Each order entry window has 6 buttons and a quantity box.  I have programmed 10 hotkeys for these buttons quantity box.

I then have an additional 6 hotkeys programmed to select any one of the 6 windows I will use at any given time.

(Window 1 = Control)  (Window 2 = Shift Alt)  (Window 3 = Control Shift Alt)  (Window 4 = Alt)  (Window 5 = Shift)  (Window 6 = Control Shift)

So for example if I want to purchase the stock on window 1 press Control and Left Arrow to buy. Or if it’s window 2 press Shift Alt and Left Arrow to buy and so on. I actually have my bloody mouse programmable keyboard set up so that I only have to push one button for each of the six commands. But that is outside the scope of the issue I am experiencing.

Control Alt and Shift frequently stay active after releasing when using with the send command. I know this is a common issue and some have found workarounds but I am not having any luck. If anyone could help I would appreciate it very much. I have included a screen shot of the six windows. Please see the code below. The hotkeys are listed first then the functions. Thanks. 

 

image.thumb.png.0c686ae3d0ba2300b912ce052384658e.png

;------------------------------Window 1 (Control)-----------------------------------------
HotKeySet('^{NUMPADADD}', 'HotKey1')                 ;Quantity
HotKeySet('^{del}', 'HotKey2')                         ;Buy
HotKeySet('^{PGUP}', 'HotKey3')                         ;Sell
HotKeySet('^{HOME}', 'HotKey4')                         ;Flatten
HotKeySet('^{LEFT}', 'HotKey5')                         ;Limit Buy
HotKeySet('^{UP}', 'HotKey6')                         ;Limit Sell
HotKeySet('^{RIGHT}', 'HotKey7')                     ;Cancel
HotKeySet('^{NUMPADDIV}', 'HotKey8')                     ;500
HotKeySet('^{NUMPADMULT}', 'HotKey9')                     ;1000
HotKeySet('^{NUMPADSUB}', 'HotKey10')                     ;1500

;------------------------------Window 2 (Shift Alt)--------------------------------------
HotKeySet('+!{NUMPADADD}', 'HotKey21')                ;Quantity
HotKeySet('+!{del}', 'HotKey22')                    ;Buy
HotKeySet('+!{PGUP}', 'HotKey23')                    ;Sell
HotKeySet('+!{HOME}', 'HotKey24')                    ;Flatten
HotKeySet('+!{LEFT}', 'HotKey25')                    ;Limit
HotKeySet('+!{UP}', 'HotKey26')                        ;Limit
HotKeySet('+!{RIGHT}', 'HotKey27')                    ;Cancel
HotKeySet('+!{NUMPADDIV}', 'HotKey28')                    ;500
HotKeySet('+!{NUMPADMULT}', 'HotKey29')                    ;1000
HotKeySet('+!{NUMPADSUB}', 'HotKey30')                    ;1500

;------------------------------Window 3 (Control Alt Shift)---------------------------
HotKeySet('^!+{NUMPADADD}', 'HotKey41')                ;Quantity
HotKeySet('^!+{del}', 'HotKey42')                        ;Buy
HotKeySet('^!+{PGUP}', 'HotKey43')                    ;Sell
HotKeySet('^!+{HOME}', 'HotKey44')                    ;Flatten
HotKeySet('^!+{LEFT}', 'HotKey45')                    ;Limit
HotKeySet('^!+{UP}', 'HotKey46')                        ;Limit
HotKeySet('^!+{RIGHT}', 'HotKey47')                    ;Cancel
HotKeySet('^!+{NUMPADDIV}', 'HotKey48')                    ;500
HotKeySet('^!+{NUMPADMULT}', 'HotKey49')                    ;1000
HotKeySet('^!+{NUMPADSUB}', 'HotKey50')                    ;1500

;------------------------------Window 4 (Alt)-----------------------------------------
HotKeySet('!{NUMPADADD}', 'HotKey61')                ;Quantity
HotKeySet('!{del}', 'HotKey62')                        ;Buy
HotKeySet('!{PGUP}', 'HotKey63')                    ;Sell
HotKeySet('!{HOME}', 'HotKey64')                    ;Flatten
HotKeySet('!{LEFT}', 'HotKey65')                    ;Limit
HotKeySet('!{UP}', 'HotKey66')                        ;Limit
HotKeySet('!{RIGHT}', 'HotKey67')                    ;Cancel
HotKeySet('!{NUMPADDIV}', 'HotKey68')                    ;500
HotKeySet('!{NUMPADMULT}', 'HotKey69')                    ;1000
HotKeySet('!{NUMPADSUB}', 'HotKey70')                    ;1500

;------------------------------Window 5 (Shift)----------------------------------------
HotKeySet('+{NUMPADADD}', 'HotKey81')                ;Quantity
HotKeySet('+{del}', 'HotKey82')                    ;Buy
HotKeySet('+{PGUP}', 'HotKey83')                    ;Sell
HotKeySet('+{HOME}', 'HotKey84')                    ;Flatten
HotKeySet('+{LEFT}', 'HotKey85')                    ;Limit Buy
HotKeySet('+{UP}', 'HotKey86')                        ;Limit Sell
HotKeySet('+{RIGHT}', 'HotKey87')                    ;Cancel
HotKeySet('+{NUMPADDIV}', 'HotKey88')                ;500
HotKeySet('+{NUMPADMULT}', 'HotKey89')                ;1000
HotKeySet('+{NUMPADSUB}', 'HotKey90')                ;1500

;------------------------------Window 6 (Control Shift)--------------------------------
HotKeySet('^+{NUMPADADD}', 'HotKey101')                ;Quantity
HotKeySet('^+{del}', 'HotKey102')                    ;Buy
HotKeySet('^+{PGUP}', 'HotKey103')                    ;Sell
HotKeySet('^+{HOME}', 'HotKey104')                    ;Flatten
HotKeySet('^+{LEFT}', 'HotKey105')                    ;Limit Buy
HotKeySet('^+{UP}', 'HotKey106')                    ;Limit Sell
HotKeySet('^+{RIGHT}', 'HotKey107')                    ;Cancel
HotKeySet('^+{NUMPADDIV}', 'HotKey108')                ;500
HotKeySet('^+{NUMPADMULT}', 'HotKey109')                ;1000
HotKeySet('^+{NUMPADSUB}', 'HotKey110')                ;1500

;#####################################################################################
While 11
    sleep(50)
WEnd
;#####################################################################################


;------------------------------Window 1-----------------------------------------------
Func HotKey1()  ;Quantity
            MouseClick('primary', 220, 682, 1, 1)     ;Quantity
            MouseClick('primary', 220, 682, 1, 1)     ;Quantity
            MouseClick('primary', 220, 682, 1, 1)     ;Quantity
            Send("{del}{del}{del}{del}")                  ;Delete All
    EndFunc

Func HotKey2()
            MouseClick('primary', 150, 830, 1, 1)     ;Buy
EndFunc

Func HotKey3()
            MouseClick('primary', 318, 834, 1, 1)     ;Sell
EndFunc

Func HotKey4()
            MouseClick('primary', 462, 837, 1, 1)     ;Flatten
EndFunc

Func HotKey5()
            MouseClick('primary', 154, 762, 1, 1)     ;Join the Bid
EndFunc

Func HotKey6()
            MouseClick('primary', 345, 762, 1, 1)     ;Join the Ask
EndFunc

Func HotKey7()
            MouseClick('primary', 160, 900, 1, 1)     ;Cancel
EndFunc

Func HotKey8()  ;Quantity 500
            MouseClick('primary', 220, 682, 1, 1)     ;Quantity
            MouseClick('primary', 220, 682, 1, 1)     ;Quantity
            MouseClick('primary', 220, 682, 1, 1)     ;Quantity
            Send("{del}{del}{del}{del}")                  ;Delete All
            Send("{5}{0}{0}{enter}")
    EndFunc

Func HotKey9()  ;Quantity 1000
            MouseClick('primary', 220, 682, 1, 1)     ;Quantity
            MouseClick('primary', 220, 682, 1, 1)     ;Quantity
            MouseClick('primary', 220, 682, 1, 1)     ;Quantity
            Send("{del}{del}{del}{del}")                  ;Delete All
            Send("{1}{0}{0}{0}{enter}")
    EndFunc

Func HotKey10()  ;Quantity 1500
            MouseClick('primary', 220, 682, 1, 1)     ;Quantity
            MouseClick('primary', 220, 682, 1, 1)     ;Quantity
            MouseClick('primary', 220, 682, 1, 1)     ;Quantity
            Send("{del}{del}{del}{del}")                  ;Delete All
            Send("{1}{5}{0}{0}{enter}")
    EndFunc

;------------------------------Window 2-----------------------------------------------
Func HotKey21()
            MouseClick('primary', 242, 168, 1, 1)     ;Quantity
            MouseClick('primary', 242, 168, 1, 1)     ;Quantity
            MouseClick('primary', 242, 168, 1, 1)     ;Quantity
            Send("{del}{del}{del}{del}")                  ;Delete All
    EndFunc

Func HotKey22()
            MouseClick('primary', 147, 318, 1, 1)     ;Buy
EndFunc

Func HotKey23()
            MouseClick('primary', 303, 320, 1, 1)     ;Sell
EndFunc

Func HotKey24()
            MouseClick('primary', 460, 315, 1, 1)     ;Flatten
EndFunc

Func HotKey25()
            MouseClick('primary', 166, 246, 1, 1)     ;Join the Bid
EndFunc

Func HotKey26()
            MouseClick('primary', 354, 251, 1, 1)     ;Join the Ask
EndFunc

Func HotKey27()
            MouseClick('primary', 153, 392, 1, 1)     ;Cancel
EndFunc

Func HotKey28()  ;Quantity 500
            MouseClick('primary', 242, 168, 1, 1)     ;Quantity
            MouseClick('primary', 242, 168, 1, 1)     ;Quantity
            MouseClick('primary', 242, 168, 1, 1)     ;Quantity
            Send("{del}{del}{del}{del}")                  ;Delete All
            Send("{5}{0}{0}{enter}")
    EndFunc

Func HotKey29()  ;Quantity 1000
            MouseClick('primary', 242, 168, 1, 1)     ;Quantity
            MouseClick('primary', 242, 168, 1, 1)     ;Quantity
            MouseClick('primary', 242, 168, 1, 1)     ;Quantity
            Send("{del}{del}{del}{del}")                  ;Delete All
            Send("{1}{0}{0}{0}{enter}")
    EndFunc

Func HotKey30()  ;Quantity 1500
            MouseClick('primary', 242, 168, 1, 1)     ;Quantity
            MouseClick('primary', 242, 168, 1, 1)     ;Quantity
            MouseClick('primary', 242, 168, 1, 1)     ;Quantity
            Send("{del}{del}{del}{del}")                  ;Delete All
            Send("{1}{5}{0}{0}{enter}")
    EndFunc


;------------------------------Window 3-----------------------------------------------

Func HotKey41()
            MouseClick('primary', 866, 680, 1, 1)     ;Quantity
            MouseClick('primary', 866, 680, 1, 1)     ;Quantity
            MouseClick('primary', 866, 680, 1, 1)     ;Quantity
            Send("{del}{del}{del}{del}")                  ;Delete All
    EndFunc

Func HotKey42()
            MouseClick('primary', 773, 828, 1, 1)     ;Buy
EndFunc

Func HotKey43()
            MouseClick('primary', 940, 826, 1, 1)     ;Sell
EndFunc

Func HotKey44()
            MouseClick('primary', 1088, 825, 1, 1)     ;Flatten
EndFunc

Func HotKey45()
            MouseClick('primary', 789, 753, 1, 1)     ;Join the Bid
EndFunc

Func HotKey46()
            MouseClick('primary', 974, 754, 1, 1)     ;Join the Ask
EndFunc

Func HotKey47()
            MouseClick('primary', 783, 889, 1, 1)     ;Cancel
EndFunc

Func HotKey48()  ;Quantity 500
            MouseClick('primary', 866, 680, 1, 1)     ;Quantity
            MouseClick('primary', 866, 680, 1, 1)     ;Quantity
            MouseClick('primary', 866, 680, 1, 1)     ;Quantity
            Send("{del}{del}{del}{del}")                  ;Delete All
            Send("{5}{0}{0}{enter}")
    EndFunc

Func HotKey49()  ;Quantity 1000
            MouseClick('primary', 866, 680, 1, 1)     ;Quantity
            MouseClick('primary', 866, 680, 1, 1)     ;Quantity
            MouseClick('primary', 866, 680, 1, 1)     ;Quantity
            Send("{del}{del}{del}{del}")                  ;Delete All
            Send("{1}{0}{0}{0}{enter}")
    EndFunc

Func HotKey50()  ;Quantity 1500
            MouseClick('primary', 866, 680, 1, 1)     ;Quantity
            MouseClick('primary', 866, 680, 1, 1)     ;Quantity
            MouseClick('primary', 866, 680, 1, 1)     ;Quantity
            Send("{del}{del}{del}{del}")                  ;Delete All
            Send("{1}{5}{0}{0}{enter}")
    EndFunc

;------------------------------Window 4-----------------------------------------------

Func HotKey61()
            MouseClick('primary', 860, 161, 1, 1)     ;Quantity
            MouseClick('primary', 860, 161, 1, 1)     ;Quantity
            MouseClick('primary', 860, 161, 1, 1)     ;Quantity
            Send("{del}{del}{del}{del}")                  ;Delete All
    EndFunc

Func HotKey62()
            MouseClick('primary', 772, 314, 1, 1)     ;Buy
EndFunc

Func HotKey63()
            MouseClick('primary', 938, 312, 1, 1)     ;Sell
EndFunc

Func HotKey64()
            MouseClick('primary', 1089, 309, 1, 1)     ;Flatten
EndFunc

Func HotKey65()
            MouseClick('primary', 788, 245, 1, 1)     ;Join the Bid
EndFunc

Func HotKey66()
            MouseClick('primary', 978, 240, 1, 1)     ;Join the Ask
EndFunc

Func HotKey67()
            MouseClick('primary', 780, 378, 1, 1)     ;Cancel
EndFunc

Func HotKey68()  ;Quantity 500
            MouseClick('primary', 860, 161, 1, 1)     ;Quantity
            MouseClick('primary', 860, 161, 1, 1)     ;Quantity
            MouseClick('primary', 860, 161, 1, 1)     ;Quantity
            Send("{del}{del}{del}{del}")                  ;Delete All
            Send("{5}{0}{0}{enter}")
    EndFunc

Func HotKey69()  ;Quantity 1000
            MouseClick('primary', 860, 161, 1, 1)     ;Quantity
            MouseClick('primary', 860, 161, 1, 1)     ;Quantity
            MouseClick('primary', 860, 161, 1, 1)     ;Quantity
            Send("{del}{del}{del}{del}")                  ;Delete All
            Send("{1}{0}{0}{0}{enter}")
    EndFunc

Func HotKey70()  ;Quantity 1500
            MouseClick('primary', 860, 161, 1, 1)     ;Quantity
            MouseClick('primary', 860, 161, 1, 1)     ;Quantity
            MouseClick('primary', 860, 161, 1, 1)     ;Quantity
            Send("{del}{del}{del}{del}")                  ;Delete All
            Send("{1}{5}{0}{0}{enter}")
    EndFunc


;------------------------------Window 5-----------------------------------------------

Func HotKey81()
            MouseClick('primary', 1530, 687, 1, 1)     ;Quantity
            MouseClick('primary', 1530, 687, 1, 1)     ;Quantity
            MouseClick('primary', 1530, 687, 1, 1)     ;Quantity
            Send("{del}{del}{del}{del}")                  ;Delete All
    EndFunc

Func HotKey82()
            MouseClick('primary', 1433, 826, 1, 1)     ;Buy
EndFunc

Func HotKey83()
            MouseClick('primary', 1594, 829, 1, 1)     ;Sell
EndFunc

Func HotKey84()
            MouseClick('primary', 1740, 827, 1, 1)     ;Flatten
EndFunc

Func HotKey85()
            MouseClick('primary', 1448, 757, 1, 1)     ;Join the Bid
EndFunc

Func HotKey86()
            MouseClick('primary', 1644, 757, 1, 1)     ;Join the Ask
EndFunc

Func HotKey87()
            MouseClick('primary', 1467, 898, 1, 1)     ;Cancel
EndFunc

Func HotKey88()  ;Quantity 500
            MouseClick('primary', 1530, 687, 1, 1)     ;Quantity
            MouseClick('primary', 1530, 687, 1, 1)     ;Quantity
            MouseClick('primary', 1530, 687, 1, 1)     ;Quantity
            Send("{del}{del}{del}{del}")                  ;Delete All
            Send("{5}{0}{0}{enter}")
    EndFunc

Func HotKey89()  ;Quantity 1000
            MouseClick('primary', 1530, 687, 1, 1)     ;Quantity
            MouseClick('primary', 1530, 687, 1, 1)     ;Quantity
            MouseClick('primary', 1530, 687, 1, 1)     ;Quantity
            Send("{del}{del}{del}{del}")                  ;Delete All
            Send("{1}{0}{0}{0}{enter}")
    EndFunc

Func HotKey90()  ;Quantity 1500
            MouseClick('primary', 1530, 687, 1, 1)     ;Quantity
            MouseClick('primary', 1530, 687, 1, 1)     ;Quantity
            MouseClick('primary', 1530, 687, 1, 1)     ;Quantity
            Send("{del}{del}{del}{del}")                  ;Delete All
            Send("{1}{5}{0}{0}{enter}")
    EndFunc

;------------------------------Window 6-----------------------------------------------
Func HotKey101()
            MouseClick('primary', 1536, 168, 1, 1)     ;Quantity
            MouseClick('primary', 1536, 168, 1, 1)     ;Quantity
            MouseClick('primary', 1536, 168, 1, 1)     ;Quantity
            Send("{del}{del}{del}{del}")                  ;Delete All
    EndFunc

Func HotKey102()
            MouseClick('primary', 1437, 315, 1, 1)     ;Buy
EndFunc

Func HotKey103()
            MouseClick('primary', 1602, 314, 1, 1)     ;Sell
EndFunc

Func HotKey104()
            MouseClick('primary', 1764, 317, 1, 1)     ;Flatten
EndFunc

Func HotKey105()
            MouseClick('primary', 1450, 245, 1, 1)     ;Join the Bid
EndFunc

Func HotKey106()
            MouseClick('primary', 1650, 245, 1, 1)     ;Join the Ask
EndFunc

Func HotKey107()
            MouseClick('primary', 1450, 386, 1, 1)     ;Cancel
EndFunc

Func HotKey108()  ;Quantity 500
            MouseClick('primary', 1536, 168, 1, 1)     ;Quantity
            MouseClick('primary', 1536, 168, 1, 1)     ;Quantity
            MouseClick('primary', 1536, 168, 1, 1)     ;Quantity
            Send("{del}{del}{del}{del}")                  ;Delete All
            Send("{5}{0}{0}{enter}")
    EndFunc

Func HotKey109()  ;Quantity 1000
            MouseClick('primary', 1536, 168, 1, 1)     ;Quantity
            MouseClick('primary', 1536, 168, 1, 1)     ;Quantity
            MouseClick('primary', 1536, 168, 1, 1)     ;Quantity
            Send("{del}{del}{del}{del}")                  ;Delete All
            Send("{1}{0}{0}{0}{enter}")
    EndFunc

Func HotKey110()  ;Quantity 1500
            MouseClick('primary', 1536, 168, 1, 1)     ;Quantity
            MouseClick('primary', 1536, 168, 1, 1)     ;Quantity
            MouseClick('primary', 1536, 168, 1, 1)     ;Quantity
            Send("{del}{del}{del}{del}")                  ;Delete All
            Send("{1}{5}{0}{0}{enter}")
    EndFunc

 

Edited by Melba23
Added code tags
Link to post
Share on other sites

Please use this tool, when you post code.

As for your issue, you may be able to use controlsend instead of send and controlclick instead of mouseclick. Have you check with au3info.exe tool if you got access to those buttons and field ?  It would make your life way easier.

Link to post
Share on other sites

Thanks Nine. I'll try the controlsend and controlclick. The code works and I use it to trade with but when the buttons get stuck it messes me up. Like if I use Shift Alt for window 2 and it sticks without me knowing  and next I use Control for Window 1 it thinks I'm trying to place orders in window 3 which is Control Shift Alt. Another example is when I try to enter a number in the quantity box it won't type so I have to press the hotkey a second time .  Cool stuff like that. Thanks for the suggestion

Link to post
Share on other sites

I know I have been thru that.  This is why I suggested using control* function.  And btw, it is possible to reduce the number of lines of the script by 10+ times. No kidding.

Link to post
Share on other sites

I tried your suggestion but it doesn't like controlsend. Wrong number of arguments. I'll have to dig into the help file tomorrow and see what I'm doing wrong there. But I do like the idea of reducing the lines of script. I wonder how that would work. Thanks again.

Link to post
Share on other sites

In response to your first post I finally checked the au3info.exe tool and no it appears I don't have access to the buttons. The Basic Control Info is blank. It shows the window title but I think that's useless since the window titles are not static(ie they change when I type in different symbols). It does show each window coordinate so maybe I could use that but I guess if it doesn't recognize the buttons then using the control method probably won't work if I'm understanding what I'm reading about it. I might play around with SendEx and see if that helps.

Link to post
Share on other sites

That is really too bad.  Since you are doomed to use Send (unless you want to tackle yourself with UIAutomation), maybe try something like this :

While _IsPressed ("10") Or _IsPressed ("11") Or _IsPressed ("12")
    Sleep (50)
WEnd

at the beginning of each hotkey set (you can create a small func for it). See if that helps.

Edited by Nine
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...