As the title says, what is the simplest way to monitor for specific keystrokes in a 3rd party windows application?
Background: Arcmap 10.2 is notorious for crashing. There is no built in autosave functionality whilst editing features so I am often losing data. While obviously the best approach is to remember to manually save my edits periodically I would like to know if I can automate this. I have been using a simple vbscript wrapper (see below) that sends the 'ctrl+alt+shift+S' keystroke (save edits keyboard shortcut) every 5 minutes. This alleviates things somewhat though the downside is that if you are mid edit when it happens you will lose your current edit.
My thinking is that I could overcome this if I could find a way to monitor for the 'F2' key (pressed after each edit), then only issue the save edits command after this is detected. I understand that this may not be possible with vbscript. I was hoping there was an 'opposite' to SendKeys though have been unable to find anything along those lines. Any suggestions?
Dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run("""C:\Program Files (x86)\ArcGIS\Desktop10.2\bin\ArcMap.exe""")
Do While True
Wscript.Sleep 300000
objShell.SendKeys "^%+S"
Loop
Related
When I start up RStudio on Windows, it lost focus. I have to click on it before I could input anything to the console or script window. I know that Ctrl-1 to focus on the Script Window, and Ctrl-2 to focus on the console window; however, both of these two shortcuts will work as long as I click on RStudio first.
Is there anything I need to set in RStudio?
Software Environment:
RStudio Version 0.99.446
Windows 7 Ultimate 64-bit
As a kludge, you can write a VBScript which first opens RStudio and then switches the focus to it:
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.CurrentDirectory = "C:\Program Files\RStudio"
WshShell.Run """C:\Program Files\RStudio\bin\rstudio.exe"""
WScript.Sleep 200 'milliseconds
focused = WshShell.AppActivate("RStudio")
i = 1
Do While Not focused And i < 10
WScript.Sleep 100
focused = WshShell.AppActivate("RStudio")
i = i + 1
Loop
Save this to the desktop in a file with a name like ToRStudio.vbs. Then, when you click on the icon, it opens up Rstudio and then tries to repeatedly switch focus to the RStudio window. In my original version of the code, I relied on a fixed time delay before issuing a single call to AppActivate. But, I discovered that when my workspace saved from my last session was large then my VBScript would finish executing before RStudio was ready. With the above loop, it repeatedly tries to grab focus before timing out. Since I put in the loop, it has had a 100% success rate in opening RStudio with the proper focus. In some debugging code I removed, the variable i never once got above 3 in 10 consecutive attempts.
Obviously, you might have to change the path names, and tweak the timings.
In my comment above I said that certain things about how RStudio handled focus struck me as counterintuitive. Since then I discovered RStudio's option to automatically switch focus to console on sourcing. The lack of doing this by default is what I had in mind. The issue in this question was the only remaining focus issue for me. I'm somewhat used to it by now, so I'm not sure if I'll actually use this VBS script.
I'm trying to execute a VBScript by a Logitech UberOptions hotkey, but of course, because of the SendKeys numberlock bug, the nice little huge Logitech NumLock toggle graphic strews itself over my screen. It doesn't look pretty. I assume an alternative to SendKeys would remedy that.
However, a real problem exists when the vbs tries to boot 2 exe's. It properly launches WOMic AND Jarvis, but Jarvis force closes milliseconds after the boot, WOmic still remains.
The final line of code is where I "auto-connect" to my microphone server (on my android) through the menu bar of the WOMic GUI.
What's an alternative to SendKeys in this scenario?
Here is my script:
Set oShell = CreateObject("WScript.Shell")
oShell.Run("""C:\Program Files (x86)\JARVIS\CustomizeableJarvis.exe""")
WScript.Sleep 250
oShell.Run("""C:\Program Files (x86)\WOMic\womicclient.exe""")
WScript.Sleep 500
oShell.AppActivate "WO Mic Client 2.10"
WScript.Sleep 100
oShell.SendKeys "%cc~"
Totally forgot about this post, I suppose I can answer my own question now.
Anyone viewing this should just opt to use AutoHotKey. MUCH better to accomplish what I was trying to do.
I want to write an app that displays the default Windows Properties sheet, I can't find much info on doing it the normal programmatic way, so I'm thinking maybe shell out to a command-line call; does anyone know the Windows command-line to call up a file's property/details window? Not having any luck searching for it.
This window here:
In a general sense, there are two methods for going about this. How you specifically accomplish it (i.e. PowerShell, C#, etc) is up to you.
Call the ShellExecute function on the file with the PROPERTIES verb.
Call the SHObjectProperties function on the file.
Examples of both can be found here in AutoIt: http://www.autoitscript.com/forum/topic/118673-open-a-files-properties-window/
It appears that there IS no direct command-line call that can do this, so I whipped up a quick little VBScript to do it, since it appeared to be the quickest and easiest way to achieve the end result (at least for my specific need).
The VBScript simply sends the Windows Shortcut Alt + Enter; so, when a file is highlighted it'll automatically use that file as the one to send the shortcut to.
For anyone else who may want to do the same, just paste the following into a new text file and save it as a .vbs file:
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.SendKeys "%{ENTER}"
For anyone interested in an even better solution, I ended up writing a small command-line app in VB.NET to do this, here's a link to it's full info + the source code: https://geekdrop.com/x/props
I have been trying (with limited resources) to use VBScript and VBA commands to send keyboard functions to a remote citrix terminal. - This, as I've discovered is a known restriction and I've found various articles which give an alternative method via C++ and scancodes to overcome the restriction.
The main issue is, I don't have access to C++.
Is there a solution that will allow this with VBScripts and/or VBA?
I've considered many options, including using the windows virtual keyboard (this didn't work) and installing a virtual keyboard driver in windows (well out of my depth).
Here is one of the articles which discuses the scancodes, using C++:
http://www.codeproject.com/Tips/310817/SendKeys-using-ScanCodes-to-Citrix
I am at a loss and anyone who can help would be a super hero...If a super heroes' main appeal was to be a geek god. :)
Any help is appreciated!!!
Cheers.
****UPDATE****
Hello,
I've done a little more digging...
...The Citrix ICA Client terminal window isn't receiving the VBScript sendkeys commands but if I manually press alt in the terminal after executing the script (with a 2 second pause), for example:
*Set objShell = WScript.CreateObject("WScript.Shell")
WScript.Sleep 2000
objShell.SendKeys ("e")
objShell.SendKeys "(P)"*
The above can access the 'file', 'edit', etc menu options on the tool bar within the terminal window.
This to me suggests that the issue isn't a privilege issue and I'd think that there is perhaps hope yet for the sendkeys method?
Having looked further into this, there is some documentation re: ini file settings on the Citrix site with regards to Citrix ICA clients.
One of the articles can be found below:
http://support.citrix.com/article/CTX129166
I've had a play around and there does seem to be a few ini files which list keyboard mappings, DLL files, virtual key passthrough as well?
One of the sections of the 'module' ini file contained the following:
[KeyboardLayout]
(User Profile)=0x00000000
(Server Default)=0xFFFFFFFF
There were other codes, including various languages, British, US-International etc.
This was then followed by a list of DLL codes e.g:
kbduk.dll=0x00000809
And finally, Language IDs, e.g:
eng=0x00000809
I am guessing (hoping) that there would be a way to amend the ini settings that will allow for the sendkeys to be received in the terminal fields and not just the toolbar menus.
As before, any help is appreciated....I am slowly going insane over this one!!!
Cheers!
Bullet pointed solution
What is required:
On screen keyboard (OSK.EXE) windows app
VBScript (not essential but preferred by me as controling script)
VBA (to move the mouse)
Set OSK to receive 'hover' commands
Set VBA code to move mouse to specific co-ordinates
Use VBScript to control when specific subs from the VBA XLS file are run. - This can be set to run in the background without the requirement for manual opening of the file etc.
Set Citrix Xenapp terminal as active window and key presses should send!
Cheers all!
I would like to operate a (Windows) Desktop program. Because i use this on a daily basis to do some simple operaition. (Open a file PDF file, render it and save it in another folder).
I would like to do this by using somekind of service or script. I have been looking into VBscript to do this but i'm getting stuck at some operations that are normally done by users.
For example if i would like to open a file a user would go to File > Open and select the desired file. Off course the script could go to file and open but how do you select a certain file (the newest file in a certain folder).
Is it possible to have a piece of code to do these operations within a Desktop program or am i trying to do something impossible or maybe i'm using the wrong tools. Below a piece off testcode for what i'm trying to accomplish.
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run """C:\Program Files (x86)\programname.exe"""
wsh.sleep 1000 ' wait 1 second
WshShell.AppActivate """Program name"""
WshShell.SendKeys "^o" ' Open file
Any help is greatly appreaciated.
You are trying to control an application through its GUI, but it is not designed for that.
Having said that, I estimate this will be a nightmare if you do not use tools (or an app :-) ) explicitely created for that purpose, a la test robots like HP QTP or automation tools like Autoit http://www.autoitscript.com/site/autoit.
For example, if your application occasionally flushes the keyboard buffer, you might need to wait for some GUI event before sending the keystroke. This kind of synchronization is not accomplishable using vbscript only.