Send windows key in vbs? - vbscript

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}"

Related

AutoHotKey: make Win+Tab act as Alt+Tab, but remap all other Win+ combinations as Ctrl+

I am trying to make my MacBook in Windows behave similar to macOS: so I can switch between apps using Win+Tab (i.e., replicate the Alt+Tab action), but have all the Ctrl+... actions (like, Ctrl+C, Ctrl+V, Ctrl+Z, etc) be accessible using the Win key (Win+C, Win+V, Win+Z).
In other words, I am trying to :
Remap Win key to Ctrl in all key combinations, but also
Have the Win+Tab act exactly as Alt+Tab (and I don't care if Ctrl+Tab stops
working as Ctrl+Tab, because I am not using that key combination at
all).
I am able to separately individually achieve 1. using LWin::Ctrl, and 2. using LWin & Tab::AltTab, but I cannot make them work together. Whenever I have something like
LWin::Ctrl
LWin & Tab::AltTab
or
LWin::Ctrl
Ctrl & Tab::AltTab
it just stops working, I am using Windows 10.
Did you try to use the symbols like documented here?
For your snippet that would mean:
LWin::Ctrl
LWin & Tab::Send, !{Tab}
There is a problem with this, as it simulates closed keystokes (regard !{Tab} as {Alt Down}{Tab}{Alt Up}. If you want to press and hold Win and then use Tab (or eventually tab multiple times), this doesn't work. To adress this issue, I found three main workarounds:
)
Let Alt stick to being pressed down:
LWin::Ctrl
LWin & Tab::Send, {Alt Down}{Tab}
LWin & Capslock::Send, {Alt Up} ;Suppose you won't use that hotkey elsewhere
)
Use something this solution by 2501:
h::AltTabMenu ; Opens the menu. Press second time to close.
n::AltTab ; Alt-Tabs through forwards
m::ShiftAltTab ; Alt-Tabs through backwards
The underlying principles/functionalities are documented here.
) Dig into AHK really deep: here (which is referenced in 1)
Annotation: Be aware that
<#::Ctrl
<#Tab::!Tab
does not work as Windows then handles the win key on its own first. You can verify This by testing:
<#::
MsgBox test
return
<#Tab::
MsgBox test
return

How to Move the mouse using VBScript

I am trying to move the mouse using VBScript. I tried to use Sendkeys "{CLICK LEFT , x , y}" and Sendkeys "{MOVETO, 10 , 20}" but it isn't working i also tried to use MouseKeys, so i could move it with the keyboard and therefore use Sendkeys to activate it but it also did not work (the mousekeys numpad is not moving the mouse). I've tried everything I know and what i could research elsewhere, so now I hope one of you can answer this for me. thxs
One possible way to move the mouse is:
Dim Excel: Set Excel = WScript.CreateObject("Excel.Application")
Excel.ExecuteExcel4Macro "CALL(""user32"",""SetCursorPos"",""JJJ"",""xxx"",""yyy"")"
-->xxx = X Position
| yyy = y Position
The only disadvantage is that you need Microsoft Excel to run this script...
Hope I could help you
VBScript can't do this natively. You'd have to do some calls to the Windows API or some other library that can do this for you.
As an alternative, you may want to consider a different scripting language, like AutoHotKey which can do this in one simple line of code for you.

vb6: interrupt endless msgbox loop

I am writing a program in VB6.
By mistake many times my code contains an endless loop, inside which there is a message box. For example:
while a>0
msgbox "a is positive"
wend
Then I press the play/run and I realize what has happened. Is there any way to stop the debugging/running of my program?
The only thing that works so far is Ctrl+Alt+Del and end task. But this way the whole visual basic closes and I lose my unsaved data. (please don't comment that I should save my program more often. I know it (now)).
Edit: I found on the internet that maybe esc or ctrl+c or ctrl+break could do the job. The first two do nothing and my laptop doesn't have a break key
Solution: I have the insert key in my laptop. on the key there is also written pause for use along with the Fn key. So I was able to break the application by pressing Ctrl+Fn+Insert (which maybe could be translated in Ctrl+Pause)
edit: link to photo of my keyboard:
ctrl + break will work. If you don't have those keys, use the on screen keyboard.
Start | Run | osk
Then press ctrl + break.

How to hijack the Caps Lock key for Cut, Copy, Paste keyboard operations

Here is what I am trying to accomplish:
To Copy, press and release Caps Lock ONCE
To Paste, press and release Caps Lock TWICE, quickly
To Cut, press Ctrl+Caps Lock
The reason I want to do this is often times i find my self looking down to press the correct X/C/V key, since they're all next to each other (atleast on a QWERTY keyboard).
How can I do this on a standard keyboard (using Windows), so that it applies to the entire system and is transparent to all applications, including to Windows Explorer? If not possible with a standard keyboard, can any of the "programmable numeric keypads" do this you think?
In the above, by "transparent" I mean "the application should never know that this keystroke was translated. It only gets the regular Ctrl+X/C/V code, so it behaves without any problems".
Ps. Not sure of all the tags that are appropriate for this question, so feel free to add more tags.
SOLVED. UPDATE:
Thank you to #Jonno_FTW for introducing me to AutoHotKey.
I managed all three requirements by adding the following AHK script in the default AutoHotKey.ahk file in My Documents folder:
Ctrl & CapsLock::
Send ^x
Return
CapsLock::
If (A_PriorHotKey = A_ThisHotKey and A_TimeSincePriorHotkey < 1000)
Send ^v
Else
Send ^c
Return
That was easy!
NOT COMPLETELY SOLVED. UPDATE:
The above works in Notepad, but NOT in Explorer (copying files for example) or MS Office (even text copying does not work). So, I need to dig around a bit more into AutoHotKey or other solutions. Will post a solution here when I find one.
In the meantime, if someone can make AutoHotKey work for everything I need, please reply!
ALL SOLVED. UPDATE:
All I had to do was to change the capital "C"/X/Z to lowercase "c"/x/z. So Send ^C became Send ^c. It now works in ALL programs inlcuding Windows Explorer! Fixed code above to reflect this change.
I believe the program you are looking for is AutoHotkey.
You need a Global Keyboard Hook.
Very nice! Been looking for something like this for a while.
My script is slightly different, making use of shift or control combinations for cut/copy, then CapsLock on its own is always paste.
Ctrl & CapsLock::
Send ^x
Return
Shift & CapsLock::
Send ^c
Return
CapsLock::
Send ^v
Return
If you wanted to retain the option of retaining the Caps Lock function, I presume you could always remap e.g. Alt-CapsLock for this. I couldn't get it to toggle correctly when I tried it though.

Favorite Windows keyboard shortcuts [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I'm a keyboard junkie. I love having a key sequence to do everything. What are your favorite keyboard shortcuts?
I'll start by naming a couple of mine:
1 - Alt-Space to access the windows menu for the current window
2 - F2 to rename a file in Windows Explorer
Win + Pause/Break to bring up computer information and to access environment variables under the Advanced tab.
Win + R to go straight to the run box (though I barely use this anymore since I started with Launchy).
Of course Alt + Tab but also Alt + Shift + Tab for going backwards.
Oh, and personally, I hate Ctrl + F4 for closing tabs - too much of a pinky stretch.
Oh and try Win + Tab on Windows 7 (with Aero on).
Win + 1 .. 9 -- Start quick launch shortcut at that index (Windows Vista).
Ctrl + Scroll Lock, Scroll Lock -- Crash your computer: Windows feature lets you generate a memory dump file by using the keyboard
#gabr -- Win + D is show desktop, Win + M minimizes all windows. Hitting Win + D twice brings everything back as it has only shown the desktop window in front of the other windows.
Alt-F4 to close a program.
WindowsKey + L to lock my workstation
Ctr-Shift-Ins to copy text from a textbox
Alt-Print Screen to capture a shot of just a window
WindowsKey + R to open the "Run" dialog (XP Pro only- does something else on XP Home)
Win-D to minimize all applications
Ctrl-Shift-Esc to open Task Manager
Win-L to lock the computer..
To maximize a window: Alt+Space, X
To restore a window: Alt+Space, R
To minimize a window: Alt+Space, N
To close a window: Alt+Space, C
I try to stick to my keyboard as well. I frequently use...
Win+L to Lock my system
Alt+F4 to close a program
Win+R to launch from the Run Window (Used for frequent programs instead of going through QuickLaunch)
F2 to rename a file
Win+D to go to Desktop
Alt+Tab and Alt+Tab+Shift to cycle through open programs
Visual Studio
Alt, D (debug), P (process), W (webdev process)
Alt, T (Tools), P (process), W (webdev process) for VS 2008
Alt, M, O to collapse to definitions
F5 to launch
F9, F10, and F11 for stepping through debugger
Alt+K, D to format a document
Alt+K, C to comment
Alt+K, U to uncomment
Browser
Alt+W to close tab
F6 to focus on the address bar
How is this not here?
+Pause to System Information. Then the system PATH variable is only 2 clicks away (Advanced system settings,Environment Variables...)
F4 in windows explorer to access the location bar trivially.
Menu key (next to the right-hand windows key) + W + F to create a new folder in explorer.
Win + E to open an Windows Explorer reference
Win + R from the Run box
Ctrl + Esc to open the start menu
And, of course, Alt + F4 to close things.
A few basic keyboard shortcuts for clipboard operations, text selection, and navigation that work in most Windows programs:
Clipboard
Ctrl+X - Clipboard Cut
Ctrl+C - Clipboard Copy
Ctrl+V - Clipboard Paste
Selecting Text
Ctrl+A - Select All (in the current field or document)
Shift+[navigate with ▲/▼, Home/End, or Pg Up/Pg Dn] - Select text between the caret's previous and new positions. Continue to hold Shift and navigate to select more text.
Navigation
Ctrl+left arrow / Ctrl+right arrow - Move the caret to the previous/next word
Ctrl+Home / Ctrl+End - Go to beginning/end of the current field or document
Bonus Tip!
Before submitting a web form where you've entered a lot of text into a text field (for example, an email in a web-based mail client -- or a new question or answer on Stack Overflow!), do a quick Ctrl+A, Ctrl+C on the field. That way, if something goes wrong with the submit (even if the browser crashes), you haven't lost your work -- you have a copy of it sitting on the clipboard.
Ctrl+Shift+Esc to go straight to the task manager without any intermediate dialogs.
In calc, F5, F6, F7, F8 cycle between Hex, Dec, Oct, Bin mode.
I use the free AutoHotKey, then I define my own shortcuts:
dobule tap F4 quickly => Close active Windows (like Alt+F4 but with one finger only)
double tap Right Alt quickly => Find and Run Robot task manager
F12 => open Find and Run Robot Locate32 plugin (I use it like a very lightweight desktop search)
Ctrl+Up / Down in a command window => scroll back / forward command line like the mouse wheel
Ctrl+w in a command windows => close window
etc.
For when you have a window stuck under an appbar and can't get at that window's system menu to move it:
alt-spacebar -> M -> arrow keys -> return
On Windows Vista, if you bring up the Start menu and search for a program, pressing Ctrl+Shift+Enter will run the selected program as Administrator. So to open an Administrator command prompt:
Windows key, type "cmd", Ctrl+Shift+Enter
My personal favourite is WinKey, U, Enter - shuts Windows down! ;-)
win+M to minimise all. Useful for quick trips to the desktop.
+[type name of program] to launch a program in Vista
+E for explorer
+F for find
Alt+Tab to swap between programs
Ctrl+Tab to swawp between tabs
Not really a 'Windows' shortcut, but the Ctrl+Alt+numpad and Ctrl+Alt+[arrows] to move and resize windows and move them to another monitor using WinSplit Revolution are absolutely great. I would never use large or multiple monitors without them.
Ctrl + Shift + ESC : Run Task Manager
Ctrl/Shift + Insert : Copy/Paste
Shift + Delete : Cut (text)
Win + L : Lock System
Win + R : Run
Ctrl + Pause Break : Break Loop (Programming)
Ctrl + Tab : Tab Change
Win+Pause/Break for System Properties
Win+E: open windows explorer
Win+F: find
Win+R: run
Win+M: minimize all windows
Win+Shift+M: restore all windows
Alt+F4: close program
Alt+Tab: switch between tasks
Ctrl+Alt+Del: task manager
Repeat Ctrl + Alt + Del Twice!
Many say that Win-D minimises all applications. Not true. It simply shows the desktop. Use Win-M to minimise all open windows. Use Win-Shift-M to restore them to their previous state.
By the way, did you notice that the Sift key can be combined with most of the usual shortcuts? e.g. Alt+Tab : cycle through applications 1->2->3->4->...1 Add Shift to the shortcut and you will be cycling in the opposite direction 1<-2<-3<-4<- ...1
Control+Tab to switch between Tabs in most Windows applications (sadly not in Eclipse) - you can already guess what Ctr+Shift+Tab will do. Especially handy in Firefox, IE, etc... where you have more than one Tab open and try going to the previous one. Very handy.
And one more tip, this is soooo handy, I love it. Only found out about it a couple of weeks ago:
FireFox users: tired of rightclick->Open Link in New Tab?
Click a link with MIDDLE mouse button and it will open in a new tab (depends on your Tabs settings in Tools->Options but by default would work). The magical thing about this is that it works even for the browser's Back button! Also when you type a search term into the Google box (usually in top right corner) and middle-click the search button, the search results are opened in a new tab. Closing tabs is also much easier with the middle mouse button (of course you can do Ctrl+W but sometimes the mouse is simply in your hand). You don't have to click the tab's red button to close it. Simply middle-click anywhere on the tab and it will be closed.
EDIT
I just tried the middle button in IE 7 and seems to work just like it does in FF, except for the Back-button and Search widget.
Ctrl + Shift + Esc -> Open Task Manager
Ctrl + W -> closes windows in MDIs where Ctrl+F4 doesn't work
Those and the Win + Number is Vista are used constantly.
Also a nice trick is Win + Tab -> cycles through program groups on task bar in Windows Xp and Server 2003. (i.e. same as Vista without the previews).
It's not a keyboard shortcut, but my favourite trick is to bind the large thumb button on the rat to move window, the smaller thumb button to resize. That way, windows can be moved and resized very easily and naturally. You can probably to that in windows too.
As for keyboard tricks, I use right ctrl+keypad to pick (one of nine) virtual screens. Very quick and natural.
In any dialog with tabs, Ctrl-Page Up/Down to cycle between the tabs.
Not really an answer, but a hint for a good source to look from - if no one cited it above wikipedia has all ( for the most important OS's) - not the best
I don't have favorites among keyboard shortcuts -- they are all utility entities to me...
Except for +L, which means another coffee break!
Windows
Windows right click key, next to the right alt can be very useful.
For the noobs,
tab and shift-tab to cycle through inputs
alt-tab and alt-shift-tab to cycle through the windows
ctrl-tab and alt-shift-tab to cycle through the tabs
ctrl-printscreen to snapshot the entire screen
and alt-printscreen to snapshot the current window
for some dialog windows ctrl-c will copy the message
Console
alt-space then e,p to paste in windows console
alt-space then e,k to mark in console
tab and shifttab to cycle autocomplete in console
Visual Studio
ctrl-shift-f Search in files
ctrl-f Search page
F12 Goto definition of the current word
F2 Rename selected text
F4 Open properties tab for selected
Highlight section and tab or shifttab Indent a block of text
ctrl-k,d Format Document
ctrl-k,c Comment out highlighted text
ctrl-k,u,c Un-comment highlighted text
ctrl-m,o Collapse to definitions
ctrl-m,m Toggle open and close the current method/function
ctrl-alt,l Open solution pane
ctrl-alt,o Open output pane
and of course ctrl-space for intellisense
My favourites are the following (which I have not been able to spot in the responses above):
F12 Save as in Office applications
Ctrl + Home Scroll to the top of the page in most applications or go to cell A1 in Excel
Ctrl + Delete Go back to the cursor in a Word document or back to the active cell in Excel
Ctrl + Shift + End Select a whole table in Excel from its top-left corner. If the table starts at A1, use in conjunction with the above for super speedy one-handed table selecting
It's already been said, but I'm repeating F6 to go directly to the browser address bar because it rocks!

Resources