shift + arrow key - vbscript

Hi I want to automate the process of selecting some lines from "Personal Communications iSeries Access for Windows".
http://i.stack.imgur.com/doshI.jpg
Manually this can be accomplished by:-
1. selecting from mouse (Drag mouse holding LEFT mouse button)
2. Position the cursor and press SHIFT+ARROW keys(UP/DOWN/LEFT/RIGHT).
I tried to do it with VBScript in following way:-
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.SendKeys "{RIGHT 5}" 'Position the cursor
WshShell.SendKeys "+{RIGHT 5}" 'Sending SHIFT+Right Arrow five times
But the code for shift+RIGHT Arrow Keys is not working for me. It is writing 66666. Similarly for WshShell.SendKeys "+{LEFT 5}"I am getting 44444 as output.
These VBScript sendkeys commands are working fine for other windows applications(like MS Word, Notepad).
Any idea how to proceed?

Try turning NumLock on, then use the arrow keys on the numbers 4 and 6.

Related

There is another way do Copy and Paste in VBS or BAT?

I was trying to automatize some repeated fill forms that I do in my job. I automate a lot of in VBA Excel, and I wanted to do with VBS too, but the company's computer doesn't work "^{C}", eather "%{TAB}".
In resume, ALT + or CTRL+ doesn't has the common response and a lot of functions are blocked...
There is another way to Change Window and Copy/Paste?
I found the problem:
.vbs has a lot of bugs in the blocked computer.
Ctrl + C or V works better as lower case: "^{c}" & "^{v}"
And the % + something doesn't work in any way.
So worked like this way for me:
Dim WS
set WS = CreateObject("WScript.Shell")
WS.AppActivate "Protocolos - Internet Explorer" ' name of the sheet
CScript.Sleep 100
WS.SendKeys "^{c}"
CScript.Quit

Code that will allow me to Left mouse click, I can only use Notepad to write the code and java is installed

I'm trying to write a script in VBScript that executes a series of events and one of them includes a left mouse click and release.
I know that I can't use VBScript in order to do the left mouse click and I can't install any software. I am only able to use Notepad in order to do all the code writing. I do have Microsoft word as well but I don't know if you can use that to write any code.
Is there a way for me to write some simple code in another language that allows me to left mouse click and release? I'm then planning on importing this code into my VBScript and continue on from there.
What I have so far:
Option Explicit
Dim Excel, x, y
Dim s
Set Excel = WScript.CreateObject("Excel.Application")
x = "10"
y = "10"
Excel.ExecuteExcel4Macro ( _
"CALL(""user32"",""SetCursorPos"",""JJJ""," & x & "," & y & ")")
WScript.Sleep (1000)
WScript.Sleep (1000)
WScript.Echo "Stop Script, Test test"
Thanks for reading!

Send windows key in vbs?

I've looked everywhere for this, is it actually possible to do? If you press WIN + LEFT ARROW it will mount your selected window to the left of your screen, and that's exactly what I'm trying to do.
I have tried things like:
shl.sendkeys "#{LEFT}"
Because I found out that # could be for WIN just like + is for Shift and % is for Alt.
This may be a stupid question but it would help me out so much. Thank you for you time
Set Keys = CreateObject("WScript.Shell")
Keys.SendKeys("^{Esc}")
This should work, it Simulates the push of the Windows key by pushing the CTRL ^ and the ESC {Esc}keys, i don't know how to make the window mount to the left of the screen
VBScript's SendKeys doesn't support the Windows key.
You can use AutoIt instead:
Send("{#Left}")
Oh, so you want to mount the window to the left, I currently don't think there's a way to do that, but there's another shortcut for start menu, as well as windows key, it's Ctrl+Esc, ^{ESC}, you could possibly run the onscreen keyboard, then somehow tab over to the key, but it would be hard, also how about trying Alt+Space, %{SPACE}, to click the window icon then, M for move, then set the cursors position to the left of the screen, somehow? I don't currently need help moving the cursor in V.B.S., but you could Google it. Hash symbol is actually typing the symbol #, hash, tested with this. I also got help on the send-keys function, here. I have way to much researching, but I still can't find a answer. Some-one also said using "Auto hotkey", a third party program, but I don't really trust programs that can take control over your whole PC.
So I guess your options are:
Alt+Space to click window icon, then M for move, then move cursor to left side of the screen
Auto HotKey, although I don't recommend it.
Other commands, but SendKeys, in VBS,
Running a file, built in a different language to do so.
Or well, waiting-for / asking Microsoft to add it in, in the next version of Windows?!
a very late response, but here is my working effort
Dim shellObject : Set shellObject = CreateObject("WScript.Shell")
Extern.Declare micVoid, "keybd_event", "user32.dll", "keybd_event", micByte, micByte, micLong, micLong
Const KEYEVENTF_KEYUP = &H2
Const VK_LWIN = &H5B
Wait 5
Call Extern.keybd_event(VK_LWIN,0,0,0) 'press win key
Wait 5
shellObject.SendKeys "({UP})" 'right aline the window. TODO Error handlng
Wait 5
Call Extern.keybd_event(VK_LWIN,0,KEYEVENTF_KEYUP,0) 'up win key
Set shellObject = Nothing
try this
wshshell.sendkeys "{lwin}"

Using AppActivate and Sendkeys in VBA shell command

I want to switch back and forth between application with the shell command in VBA.
I am using SendKeys to do stuff in process A then move to process B, then to process A then process B. It works fine for the first iteration. When I use AppActivate to go back to process B, it actually does switch focus back to process B. HOWEVER, it ignores subsequent commands from SendKeys.
Example code:
Sub pastePDF2TXT_v3(pdfName As String, txtName As String)
Dim acrobatID
Dim acrobatInvokeCmd As String
Dim acrobatLocation As String
Dim notepadID
Dim acrobatID2
Dim notepadID2
Debug.Print "here"
acrobatLocation = "C:\Program Files\Adobe\Acrobat 9.0\Acrobat\Acrobat.exe"
acrobatInvokeCmd = acrobatLocation & " " & pdfName
acrobatID = Shell(acrobatInvokeCmd, 1)
AppActivate acrobatID
SendKeys "^a", True '^A selects everything already in the pdf file.
SendKeys "^c", True '^C copies the selection to the clipboard.
notepadID = Shell("NOTEPAD.EXE " & txtName, 1) ' invoke notepad on the text file.
AppActivate notepadID ' set the new app as teh active task.
SendKeys "^a", True '^A selects everything already in the text file.
SendKeys "^v", True '^V pastes the new stuff over the top of the old text file (deleting the old stuff)
SendKeys "%{END}", True ' makre sure last line of text file
SendKeys "{ENTER}", True
AppActivate acrobatID ' NOTE: APPEARS TO WORK UP TO THIS POINT.
SendKeys "{ENTER}", True ' NOTE: SECOND APP IGNORES SUBSEQUENT COMMANDS FROM HERE DOWN.
SendKeys "^a", True '^A selects everything already in the pdf file.
SendKeys "^c", True '^C copies the selection to the clipboard.
SendKeys "%f", True 'alt f, x to exit Notepad.exe
SendKeys "x", True
'acrobatID.Quit
Debug.Print "start second"
AppActivate notepadID ' set the new app as teh active task.
SendKeys "%{END}", True 'Go to end of text file.
SendKeys "^v", True '^V pastes the new stuff at end of file.
SendKeys "{ENTER}", True
SendKeys "^s", True
SendKeys "%f", True 'alt f, x to exit Notepad.exe
SendKeys "x", True
notepadID.Quit
acrobatID.Quit
End Sub
I know this question is old, but I have run into this same problem, but I don't think the answer that was chosen is the correct one.
When you call AppActivate, the script goes on halt, waiting for the target application to terminate. After the application is terminated, the script continues. I see no solution to this issue.
EDIT:
I use a batch-file to call CSCRIPT for the AppActivate command, and I notice you are strictly using a VBS file. Try calling CMD as a new window and pass CSCRIPT //NoLogo //B WScript.CreateObject("WSCript.shell").AppActivate("Window Name") as the argument, and see if that bypasses the issue.
Similarly, I was trying to use AppActivate on a pdf document I had opened with a shell command so that I could use SendKeys on it. It would always generate Run Time Error '5'. My solution, eventually was to NOT use AppActivate at all, in fact opening the document brings it to the forefront anyway. The problem is that the SendKeys statement executes immediately after the shell command but the pdf needs a second or two to open up. My solution is to pause the code for a couple seconds before excuting the sendkeys statement.
I used a time delay curtosy of pootle flump. Check out the thread here:
http://www.dbforums.com/microsoft-access/1219379-time-delay-vba.html
After hours of research on various forums, I could figure out that I wont be able to use Adobe library objects and functions with Adobe Reader. The only viable option left was to use Shell Commands to use "save as text" option available in the Adobe Reader's file menu. The shortcut key is Alt+f+a+x+s. I implemented these in the below code which worked perfectly, although I was required to insert delays in some steps.
Sub SavePDFasText()
Dim AdobeReaderPath As String
Dim PdfFilePath As String
Dim PDFid, NotepdId As Double
AdobeReaderPath = "C:\Program Files\Adobe\Reader 10.0\Reader\AcroRd32.exe"
PdfFilePath = "D:\PowerGenMacro\opm_11.pdf"
PDFid = Shell(AdobeReaderPath & " " & PdfFilePath, vbNormalFocus)
Application.Wait TimeSerial(Hour(Now()), Minute(Now()), Second(Now()) + 5)
'Alt+f+a+x is required to save the pdf as text in the adobe reader
SendKeys "%(FAX)", True
Application.Wait TimeSerial(Hour(Now()), Minute(Now()), Second(Now()) + 2)
SendKeys "%S", True
SendKeys "^q", True
End Sub
This might be more of a comment than an answer, but I don't seem to be allowed to "comment", so...
It's amazing you've gotten as far as you did. Chances are, you're never going to be able to make this work reliably -- period. As soon as you do make it work, something will change about how the Acrobat UI behaves in a future release, or Windows will make another change to the rules for what things can send events to what other things, and then you're hosed again.
What you are probably running into in this case is Windows trying to prevent an application stealing the focus from another when a user is apparently busy interacting with the first one. You see the same kinds of problems trying to do things like have a button in one application write data to a temporary file and open MS Word to edit it. Windows prevents the focus from transferring away from the current app and over to MS Word because you just clicked a button in the current app.
So -- instead of trying to solve this impossible technical issue, let's take a step back and ask what you were originally hoping to accomplish by doing all of this. In that way, perhaps, we can get you where you're trying to go :)
Try
sendkeys "%{tab}"
to switch windows
but then keep only 2 active windows.
or try
appactivate only after sendkeys {Tab} so that text entry box is not selected before switchibg windows cmd.
or try
try appactivate window name, 1
then sleep 2000 °to allow time to bring that window into focus
You forgot to add "DoEvents" between each sendkeys and kind of delay/wait period, to give it some time to execute.

How do I automate a right click in VBScript?

I want to automate simulation of a right click to open the context menu. Once the menu is open, select the selected action/shortcut available.
I know how to open:
WshShell.SendKeys("+{F10}");
Or using the AutoIt automation language (BASIC like):
;--on right click event
MouseClick("right")
$count = 1
Do
Send("{DOWN}")
$count = $count + 1
Until $count > 7
Send("{ENTER}")
;---select shortcut
WinWaitActive("xxxxk")
;----doing execution from the 3rd program
ControlSend("xxxxx", "", "Edit2", "123ABC")
Sleep(500)
ControlSend("xxxxx", "", "Edit3", "123ABC")
Sleep(500)
Send("{ENTER}")
Sleep(500)
WinClose("xxxxx")
WinWaitActive("xxxxx", "Close")
Send("{ENTER}")
Can I have something like this in VBScript? Too messy, I think.
your answer is in your question
WshShell.SendKeys("+{F10}");
once the right click menu is open send another key 's' (in most cases 's' is used to select/select all)
shell.Sendkeys "s"
and you're done :)
here goes the complete code
shell.Sendkeys ("+{F10}")
shell.Sendkeys "s"
the above code should work in VBScript right click automation,
i'd also like to mention that Right-Click in a title bar is equivalent to ALT+SPACE, so if you want to right click on the title bar by vbscript i'll advice you to send ALT+SPACE instead
Source: http://msdn.microsoft.com/en-us/library/8c6yea83%28VS.85%29.aspx
Right click on what?
If you are talking about files/folders (in Windows Explorer), you can do it with shell automation: DoIt or InvokeVerb

Resources