Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SendKeys Woes...help!!!

295 views
Skip to first unread message

John Smith

unread,
Jul 31, 2000, 3:00:00 AM7/31/00
to
I'm having some trouble with SendKeys in VB Script (also with VBA):

My application needs to emulate the Alt, the Ctrl, and the Shift keystrokes
(as if the user had pushed the keys on the keyboard).

I've tried using the %, ^, and + codes, respectively, but they don't work.
It seems as though SendKeys only works with ASCII codes and there is no
ASCII code for the press of the Alt key, or the Ctrl key, either. The
closest to the Shift key is ASCII 15 (shift in) and ASCII 14 (shift out),
but VBScript errors out on ASCII 14 and/or 15.

Surely there must be some workaround. I'm using WSH2. I'd really
appreciate if someone can help with this, I've already wasted over 6
playtesting and researching the issue and so far the only progress is that
now I think I know why it isn't working. Just need help with a workaround!
:-)

TIA

JS

Black

unread,
Jul 31, 2000, 3:00:00 AM7/31/00
to
John Smith,

Dim oWSHShell
Dim oWSHEnvironment
Set oWSHShell = WScript.CreateObject("WScript.Shell")
Set oWSHEnvironment = oWSHShell.Environment("SYSTEM")
oWSHShell.Run oWSHEnvironment("WINDIR") & "\NOTEPAD.EXE", 3, False 'Open
notepad.
WScript.Sleep 3000 'Wait three seconds.
oWSHShell.SendKeys "%{F4}" 'Send ALT+F4 to close the notepad program
Set oWSHShell = Nothing
MsgBox "Done!"

Hope this helps.

Thank you,

Lael Black
bl...@reg.net


"John Smith" <ye...@right.net> wrote in message
news:XC5h5.25158$5N1.8...@newsread1.prod.itd.earthlink.net...

John Smith

unread,
Aug 1, 2000, 3:00:00 AM8/1/00
to
I tried this, and I guess I left out an important part:

I can get VBScript to emulate key combinations of Shift, Control, and Alt
with normal ASCII characters, and even some special characters, such as the
F keys, but not with each other.

To switch computers with a Keyboard/Video/Mouse switch (KVM), the switch
looks for keyboard input of Control, Shift, and Alt (together, or one at a
time in any order), then a number between 1 and 4, then the enter key.

What I'm having trouble getting VBS to do is to simulate typing Control,
Shift, or Alt. The codes for these keys are: ^, +, and %, but VBS ignores
these unless you combine them with a character out of the ASCII codes.

Is there any way to get the computer to emulate these special keys?

Thanks for responding, I hope you have some more ideas--I'm all out...:-p

Cheers,

JS
"Black" <bl...@reg.net> wrote in message
news:dX5h5.68999$i5.10...@news1.frmt1.sfba.home.com...

Benn Schreiber

unread,
Aug 1, 2000, 3:00:00 AM8/1/00
to
I would be surprised if this works even if you cuold get SendKeys to do what
you want. I think that most KVM switches look for this key sequence coming
from the *real* keyboard, not from a computer connected on the other side.
I'd love to be proved wrong, of course!


"John Smith" <ye...@right.net> wrote in message

news:0_qh5.31978$ga2.8...@newsread2.prod.itd.earthlink.net...

John Smith

unread,
Aug 1, 2000, 3:00:00 AM8/1/00
to
Come to think of it, you're probably right.

Surely the KVM switch must sense the signal on the input side of the switch
(from the keyboard) and not from the output side (where it sends the
keyboard signal to the computer). I guess that's why the KVM switches
w/software control cost $200 more than mine. I better just be happy I can
control it with the keyboard instead of having to reach behind the monitor
to push the button on the box manually :-/

Oh, well, at least I learned some VBS while trying, and I found out I can
hit control, alt, and shift at the same time, instead of sequentially--that
should save a little time.

Thanks to all who helped out.

Cheers,

JS
"Benn Schreiber" <benn_sc...@hotmail.com> wrote in message
news:Opv$bxA$$GA.78@cppssbbsa04...

0 new messages