Simple script to open window and press hotkey - windows

I want to make a simple script that will run when pressing ctrl + k. This script will then press WINKEY + 3 and then press ctrl + a. I cant seem to figure out a way to do this. I was trying batch files but SendKeys method does not support the WINKEY from what I gathered. This is Windows 7 or 10 (could be using either). Thanks
For those who don't know, WINKEY + 3 opens the third pinned program on the taskbar. ctrl + a is an internal command for that program. If anyone knows of another way to do this instead of faking the key presses, feel free to enlighten me.

I believe it isn't possible in batch, but as GregHNZ said, it is easily done in autohotkey. You can easily compile it into a exe, too!
Here's the code:
^k::
SendInput #3
SendInput ^a
If this doesn't work, try putting a Sleep command inbetween them:
^k::
SendInput #3
Sleep 1000
SendInput ^a
This just makes it wait for 1 second so the program can load (adjust the time to your needs, though!).
You can download Autohotkey here.

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

Mapping RightAlt+Ctrl+a to send Ctrl+Delete?

I have the following map:
>!+a::SendInput,+{Delete}
It's supposed to send Ctrl+Delete (delete word after cursor) when I press RightAlt+Ctrl+a but instead it's sending a Ctrl+Alt+Delete signal so it's bringing up the Windows 7 menu of shutdown, start task manager etc.
How can I send the right signal?
Appreciate any help!
The problem you are facing is that Ctrl + Alt + Delete is hard coded and is uninterruptible. There's simply no way around it, if you press that sequence, even with the Command BlockInput enabled, Windows will re-enable input and execute the command...
Try:
>!^a:: ; + symbol is Shift ^ represents Ctrl key
KeyWait, RAlt ; Waits for Right Alt to be released before Ctrl Delete is sent
SendInput,{Ctrl Down}{Delete}{Ctrl Up}
Return
An alternative although it works the exact same way:
>!^a::
While (GetKeyState("RAlt", "P"))
Continue
SendInput,{Ctrl Down}{Delete}{Ctrl Up}
Return
I'll continue to pursue other options.. at the moment I can I think of no better way to do this.

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

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.

Resources