Single shift key in VBS - vbscript

I'm trying to write a vbs script that has to send the shift key once. I dont need any other key pressed after it but I can't get it to work (I want to use only vbs not any other progarm nor another language). I've tried things like:
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.SendKeys "+{}"
or
WshShell.SendKeys "+"
or
WshShell.SendKeys {+}
or
WshShell.SendKeys +
and many more but nothing seems to work.
Thank you in advance!
-Sandro Cutri

You can send a shift key (without anything else) with the Duck toolkit. It's a free webside. It "translates" your code from vbs to the ducky language (it turns it into a inject.bin file). I assume that that's what you want to do. From there you can write
SHIFT
That's all you need to write. It's important to write in CAPITAL letters.

Related

How do I stop an auto typer from ‘pyramiding’?

I’ve been looking around for an auto-typer for some fun on Discord and I found a Virtual Basic code on Youtube that functions mostly to my needs but it has one problem. It’s supposed to type a phrase and then enter and then type and enter for a set amount of times but when I test it in notepad++ it does this:
test
testtest
testtesttest
testtesttesttest
And so on until it maxes out at 17. I’m not sure what could be wrong with it because I didn’t make it and I’m not very adept with coding at all. This is the code:
set shell = createobject(“wscript.shell”)
strtext = inputbox(“What would you like the message to be?”)
strtimes = inputbox(“How many times would you like to type it?”)
if not isnumeric(strtimes) then
lol=msgbox(“Please write a number next time”)
wscript.quit
end if
msgbox “After you click Ok the message will start in 2 seconds”
wscript.sleep(2000)
for i=1 to strtimes
shell.sendkeys (strtext & “”)
shell.sendkeys (“{Enter}”)
wscript.sleep(100)
next
I’ve tried adjusting spaces and such before and after parentheses but nothing seems to change the ‘pyramid’ outcome. Any suggestions on what I could try to change or if anyone actually sees what’s wrong would be much appreciated.
The Issue you are running into is with notepad++ specifically.
shell.sendkeys (“{Enter}”)
Is triggering the Word Auto Completion.
I ran this writing to standard Notepad without issue.
Edit:
This does work in Notepad++ if you do the Enter twice.
shell.sendkeys ("{Enter}")
shell.sendkeys ("{Enter}")
Or if you add a space after the string.
shell.sendkeys (strtext & " ")

How to automatically close an OK window in VBScript?

I need to automatically close an "OK" window in a program by pressing Enter.
I tried to do that with a VBScript, but it gives me an error.
Set objshell = WshShell.Sendkeys "{Enter}" ("wscript.shell")
objshell.Run,0, True
exit
The error is:
Line: 1
Char: 34
Error: End of instruction expected
Code: 800A0401
Source: Microsoft Vbscript Compile Error
When in doubt, read the documentation. There is no intrinsic object WshShell in VBScript. You need to create a WScript.Shell instance and assign it to that variable before you can call the SendKeys method on it.
Set WshShell = CreateObject("WScript.Shell")
WshShell.SendKeys "{Enter}"
And you probably need to bring the window to which you're trying to send that keystroke to the front first using AppActivate.
Anyway, seeing how all of your 3 lines of code are entirely broken syntactically, I strongly recommend you go find a VBScript tutorial before proceeding any further.
Note also that SendKeys is a horribly unreliable method of automation. You may want to look into something like AutoIt instead.

Getting actual powershell return value in vb6?

Alright, so I have been trying to do this for a while, and I have come to the realization that this isn't really something that is often asked, and with vb6 getting phased out more and more, there seems to be less help than I would like regarding the language.
The title doesn't say it all actually, as I am looking to do something very specific. I need to execute a shell command (that I know how to do), however, after I execute it, I want to be able to save the return value of that command as a string. For example, if the command is ipconfig, I want the entire return value of that, all the text I would see in powershell after executing that command, saved to a string in my program.
As far as I know, I need to "import" a few things, because I have to use WshShell, which I don't know where to get. So that's part of the question, what classes do I have to add and how, or if there is a way to do it without adding classes then even better. In addition, I have heard a lot about the use of CreatePipe and such regarding similar problems, but I don't know how to use it.
Basically, what I'm saying is that I am quite uneducated regarding the subject, and any insight would be much appreciated, and thanks to all who reply.
There are many ways. Using VBScript's WSHShell.Exec is the easiest.
This is VBScript but VBScript can be pasted into VB (not vice versa though).
Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec("ipconfig")
Do While oExec.Status = 0
WScript.Sleep 100
Loop
MsgBox oExec.StdOut.ReadAll
Slightly modified from help.
This is how to ping from VBS/VB
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * From win32_PingStatus where address='104.43.195.251'")
'msgbox colItems
For Each objItem in colItems
msgbox "Status" & objItem.statuscode & " Time " & objItem.ResponseTime
Next

How can I write batch output to my text cursor?

In Windows 7, ultimately I want to bind a shortcut key (Ctrl+Alt+D) to spitting out a date-time stamp of the form 20120913 1232.
The step I'm getting hung up on is having a batch file write anything to my text cursor. Currently I'm piping it to clip.exe, then I paste, but I'd like to eliminate the middle step of the clipboard. If this isn't possible, is there another way around my problem?
echo %date:~-4%%date:~4,2%%date:~7,2% %time:~0,2%%time:~3,2% | clip
You can't do it from cmd. You need to use VBS, Js or PowerShell. Here's a simple VBS script that does what you want. Just create a shortcut on the desktop that runs this VBS file and assign a shortcut key to it
Set WshShell = WScript.CreateObject("WScript.Shell")
' Switch back to the previous window. Use Alt+Esc because Alt+Tab sometimes doesn't work
' WshShell.SendKeys "%{TAB}", True
WshShell.SendKeys "%{ESC}", True
' Get the time string
Dim dt, datetime_str
dt = now
datetime_str = Year(dt) & Right("0" & Month(dt), 2) & Right("0" & Day(dt), 2)
datetime_str = datetime_str & " " & Right("0" & Hour(dt), 2) & Right("0" & Minute(dt), 2)
' Send the date string to the target window
WshShell.SendKeys datetime_str
However Autohotkey (AHK) would be a much better solution and works much faster. Here are 2 example functions that will type the datetime string to the current app
; Map Ctrl+Alt+T to send the date string
^!t::
FormatTime, currentdate,, yyyyMMdd HHmm
SendInput %currentdate%
Return
; Map Ctrl+Alt+D to send the date string
^!D::
SendInput %A_YYYY%%A_MM%%A_DD% %A_Hour%%A_Min%
Return
Save the above script as *.ahk and run it. AHK will run in the background and listen to the key sequence to do the desired action
For OP/anyone interested: http://ahkscript.org
Auto Hotkey might be what you were after. Either a vanilla complementary cmd .bat or a standalone AHK script should be able to pull data from STDOUT and SET your date syntax up, AND set the hotkey all from 1 script.
The "hotkey" section of this question might be why it hasn't been answered before, not something that can be done in Windows CLI afaik, you need "Shortcut key remapping software" which is exactly what Auto Hotkey is designed for :)
It has been a long time since I researched Shortcut key remapping in Windows, but I do remember AHK being only a handful of programs able to remap hard-coded shortcut combinations like WinKey + R, unless you code one yourself (in C++ or similar)
I also recommend a thorough dig into Rob van der Woude's site, specifically the 2 articles about redirection:
http://www.robvanderwoude.com/battech_redirection.php
and down the bottom is a link to the "Redirection overview page" which is a particularly good "cheat sheet" for redirection commands/syntax.

How do I use WScript.Shell SendKeys to send Number Pad key strokes?

I am trying to use WScript.Shell SendKeys method to emulate sending a key press from the Number Pad.
I have an application that I am writing automated testing for using QTP. It is a Web Browser based application and the input is into a Java App within the web page. The input only accepts key presses from the Number Pad and the Enter key.
So far I am using this code:
Dim strInputKey
strInputKey = "{ENTER}"
Set objWsh = CreateObject("WScript.Shell")
Browser("Launch Browser").Page("Test Application").WebElement("Item ID").Click
objWsh.SendKeys strInputKey
This works fine for sending the Enter key, but I can't quite figure out if there is a way to send Number Keys. Any help would be greatly appreciated.
I am not sure if there are any undocumented ways of achieving this. I have read http://msdn.microsoft.com/en-us/library/8c6yea83(VS.85).aspx but it doesn't go into great detail.
I don't have the rep to comment on the above answer that said
objWsh.SendKeys chr(79) & chr(80) & chr(81)
but I don't think it's correct
objWsh.SendKeys chr(79) & chr(80) & chr(81)
For a start, it sends the letters O,P,Q
And he wants numbers, like 1234567890
and the link goes to keyboard scan codes.. I think those are for knowing what key on the keyboard was pressed. They are different from ascii codes.
79,80,81 are the keyboard scan codes for some numbers on the number pad / numpad.
Chr though, uses ascii codes. not keyboard scan codes.
Furthermore, just specifying a digit, here, since it isn't done by pressing a key, it doesn't specify and needn't specify, which was key was used, since a key wasn't used.
To sendkeys some numbers (from the number pad), is just same as sending keys from the top row. You just want to send some numbers.
If all he wants to know is how to use sendkeys to send digits, then obviously.
objWsh.SendKeys 12345
or
str="12345"
objWsh.SendKeys str
But if the questioner didn't realise that objWsh.SendKeys 12345 would do it, then perhaps the questioner is just confused. I guess from the green tick, he voted an answer that is like objWsh.SendKeys "OPQ".
I am aware that this is an old question, but for the sake of haing correct questions and answers..
You'll need to use the keycodes for the number pad.
Here's a list of them:
http://www.empirisoft.com/directrt/help/_helpcontents.htm?directrt_key_codes.htm
So to send "123", you would need to do:
objWsh.SendKeys chr(79) & chr(80) & chr(81)

Resources