WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

How To
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Holding down a key

Keywords: 	   Shift Hold down Keyboard key  KEYDOWN KEY_DOWN Keyboardstate 

Question:

The issue is the need for holding down the "Shift" key until a certain window exists. I have a WinBatch program that sends a key then waits for a window to appear. The window will only appear if the user is holding down the shift key. There is a second or two between the time that the first key is sent and the appearance of the next window dialog box. The "Shift" key must be held down during this time for that window dialog box to come up. I cannot program this now using a repeated "Shift" key send string. This is the only place in the program where I have to interact with the WinBatch program manually.

I am currently using version 2000C, DllVer 3.0 cbv. Is there anything like this in this version that I may be overlooking or is this something you can add to a future version?

Answer:

Unfortunately WinBatch doesn't really have a function to hold any key down, for an extended period of time.

Since you need the to hold the Shift key down. One thing you might try is using the MousePlay function. MousePlay accepts the WIL constants @SHIFT and @CTRL in the "buttons" parameter. You can combine these constants with a mouse button constant using the bitwise OR ('|') operator to duplicate holding down the Shift or Control key while performing a mouse drag-and-drop or button click.

While !WinExist("window Title")
  ;Holds SHIFT key down for 5 Seconds
   MousePlay( "", "", "", @SHIFT, 5)
Endwhile

Question (cont...):

I tried your suggestion and it seems to work most of the time. I would still like to suggest the toggle function for the shift and ctrl keys.

I need to send a Shift/Enter and then keep holding down the Shift key until the next window comes up. So this is my current code using the tip you gave me:

WinWaitExist("Host",-1)               ;wait for the Hosts window to come up
SendKeysTo("Host","menu")             ;open the menu program and wait for
the window to come up
TimeDelay(2)                  ;wait
SendKeysTo("Host","+{Enter}") ;open the menu program and wait for the menu login window to come up
While !WinExist(menulogintitle)
   MousePlay( "", "", "", @SHIFT, 5)          ;hold SHIFT key down for 5 Seconds
Endwhile
WinActivate(menulogintitle)
SendKey(stuff)                        ;send the login string proceed.....

If I don't continue to hold down the shift key after sending Enter, then the menu login window will not come up. Once it does, I can let go of the Shift key and type in my next set of characters, etc.

When I suggested a "toggle" for Shift or Ctrl, I meant I would like a direct way to say HOLD DOWN SHIFT and LIFT UP SHIFT NOW. thus, iIn the above example, I wouldwrite ...

HOLD DOWN SHIFT
SendKey ("{ENTER}")
WinWaitExist ("menu login", -1)
LIFT UP SHIFT NOW
proceed.....

Answer (cont...)

The developer gave me the following DllCall code, to have you try.....

dll = StrCat(DirWindows(1), "user32.dll")
DllCall(dll, void:"keybd_event", long:16, long:0, long:0, long:0); shift key down
Delay(5)
DllCall(dll, void:"keybd_event", long:16, long:0, long:2, long:0); shift
key up

Let me know how it works out for you...

Resolution:

I tried the code and it seems to work fine. Here is my resultant code:
dll = StrCat(DirWindows(1), "user32.dll")
DllCall(dll, void:"keybd_event", long:16, long:0, long:0, long:0); shift key down
SendKeysTo("Host","+{Enter}")   ;open the menu program and wait for the
window to come up
While !WinExist(menulogintitle) ;Wait for the menu login tilebar to appear
   Delay(1)
Endwhile
DllCall(dll, void:"keybd_event", long:16, long:0, long:2, long:0); shift key up

Thanks to you and the developer for your responsiveness. I like working with WinBatch people.



Article ID:   W14603
Filename:   Holding down a key.txt
File Created: 2006:07:05:10:58:34
Last Updated: 2006:07:05:10:58:34