Fix Labview Alt-Tab behaviour with Autohotkey - autohotkey

Did anyone try to fix the way Labview interferes with normal Alt-Tab behaviour using Autohotkey?
Alt-Tab inside Labview puts all non-labview windows to the end of the list.
So if you have just alt-tabbed to labview window from your browser it takes
(2 × number_of_currently_open_labview_projects -1)
keystrokes to get back.

Great idea. I find that functionality annoying and there doesn't appear to be an easy fix anywhere on the web. Here's my script. Two quick notes:
I had a lot of trouble re-mapping Alt-Tab. If that's critical you can try starting here for help.
To my knowledge it's not possible to get rid of the "screen flicker" because Windows requires some delay between keystrokes.
Note: to adapt this code for various Windows - look up the "ahk_class" using the Window Spy tool included in the AutoHotkey installer .
Code
#NoEnv ; Recommended for performance and compatibility with future
AutoHotkey releases.
#Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#NoTrayIcon
#SingleInstance force
SetTitleMatchMode 2 ;partial search mode
#IfWinActive vi
#q:: ;there were issues mapping to Alt+Tab
CountOfVIs := -1
WinGet, id, list,ahk_class LVDChild,, Program Manager
Loop, %id%
{
CountOfVIs := CountOfVIs +1
}
msgbox, # of VIs open: %CountOfVIs% ;when I remove this it doesn't work - must be an AHK thing
Send {Alt down}
Loop,%CountOfVIs%
{
Send {tab}
Sleep,50 ;if this is too low it doesn't work
}
Send {Alt up}

I've recently found an article related to this problem, but unfortunately it is in Russian.
It references the following blog with a python script (+autohotkey mapping) that seems to be solving the problem without the "screen flicker".

Related

Key not gettiing sent to background window ControlSend

I'm trying to send f keys to a backgrounded game while I browse the web. The script runs and doesn't error out
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
toggle = 0
#MaxThreadsPerHotkey 2
F8::
Toggle := !Toggle
While Toggle{
ControlSend [f,Entropia.exe]
}
return
IF I run this , activate the toggle, and press f with entropia opened and say notepad as the focus the Fs are showing up in notepad and not being sent to entropia
You cannot use AHK to send keys to a background window (just like you can't type on your keyboard into a background window).
Best you can do is quickly switch over to the window (you don't have to show the window or bring it forward, just activate it briefly) then send the key and then switch back to your current window.

Visual Studio Code extension - mouse middle click go to definition

I'm searching for an extension for VS Code something like this:
https://marketplace.visualstudio.com/items?itemName=norachuga.MiddleClickDefinition
It's natively supported in WebStorm, and I want to switch to VSC and it's really annoying.
I didn't find any results on google.
Is any good tutorial or code snipped on how to create one?
Author Credit: https://github.com/danielsamuels
For those of you who are looking for a short term fix for this, I've created an AutoHotkey script which provides middle-click Go To Definition behaviour:
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#IfWinActive ahk_exe Code.exe
~MButton::
MouseGetPos, xpos, ypos
if (ypos >= 87) {
SendInput,{Click}{F12}
}
return
Copy the above contents into a file named vscode-f12-go-to-definition.ahk and run it. You'll see a green H icon in your systray which shows it's running.

Automating actions in OneNote using AutoHotKey

I want to assign keyboard shortcut to various actions in Microsoft OneNote. (Its annoying that OneNote has different keyboard shortcuts than Word and Excel). Also OneNote does not support macros. So I am trying out AutoHotKey.
I want to make selected text red, when I hit Ctrl+Alt+Shift+r. I wrote simple script file:
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#IfWinActive - OneNote$ ; ------ only in windows with title ending with "- OneNote"
^!+r::
Send, !hfcm^{PgDn}!r255{Tab}5{Tab}0{Enter} ; red (255, 0, 0)
return
#IfWinActive ; ------ end of section restricted to specific windows
But it does not do anything when I hit those keys. When I remove #IfWinActive lines, it starts working. How can I make it work only within one note?
I think you might be trying to use the regex title match mode. To use it, you'd need to specify it first on top of your script like this:
SetTitleMatchMode, RegEx
#IfWinActive, - OneNote$
^!+r::Send, !hfcm^{PgDn}!r255{Tab}5{Tab}0{Enter} ; red (255, 0, 0)
#IfWinActive
Also compacted your hotkey into a one liner, since that's what it is.
And that should work (assuming it's matching the correct title, I can't test it, I don't use OneNote)
Personally I'd recommend matching with ahk_exe though. This will (likely) make no difference in practice, but it's very convenient in my opinion.
So assuming the executable running OneNote would be named OneNote.exe (check its actual name from e.g. task manager, or with e.g. WindowSpy*) you'd do this (don't use Regex title match mode with this):
#IfWinActive, ahk_exe OneNote.exe
^!+r::Send, !hfcm^{PgDn}!r255{Tab}5{Tab}0{Enter} ; red (255, 0, 0)
#IfWinActive
* WindowSpy a neat little script that'll be found in your AHK install folder

How to make autohotkey work in "OneNote for Windows 10" app (not OneNote)?

I am trying to add a program specific shortcut, i.e. a shortcut to be used inside OneNote App only, and not the short cut for the opening of app itself.
Here is how the present script is:
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#IfWinActive, ahk_exe OneNote.exe
+Enter::
Send, {(}!+d{)}
return
But the above one works in OneNote desktop and not for the "OneNote for Windows 10" app (OW10A); how do I make it work for that store app? I am not able to find .exe for the store app to mention it in the above script.
You can use the #If- or the #IfWinActive- directive to create context-sensitive hotkeys and hotstrings:
#If WinActive("WinTitle ahk_class WinClass", "WinText", "ExcludeTitle", "ExcludeWinText")
#IfWinActive, WinTitle ahk_class WinClass, WinText, ExcludeTitle, ExcludeWinText
https://autohotkey.com/docs/commands/_If.htm
Use Window Spy to get detailled information about the program windows.
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
SetTitleMatchMode, 2 ; Title can be part of the full title
#If WinActive("- OneNote ahk_class ApplicationFrameWindow", "OneNote")
+Enter:: Send, {(}!+d{)}
; Here you can add more program specific shortcuts:
; ...
; Here you can add specific shortcuts for another program:
#If WinActive("‎- Microsoft Edge ahk_class ApplicationFrameWindow", "Microsoft Edge")
+Enter:: MsgBox, You pressed Shift+Enter in Microsoft Edge
#If ; turn off context sensitivity

Autohotkey pressing key in specific window

I run multiple windows of the same program and I want to make ahk press a specific button in all of them, for examle "0". I tried using alt tab command, it worked but only 1 time and I was not able to loop it properly. Maybe there is another better way to do make it press a key in every window?
As long as you use Internet Explorer and each IE window is separate (not all in different tabs in the same window), the following should show you how to loop through each open IE window. It will also show explorer windows, so your code can first determine what type of window before proceeding to send the keys.
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
SetTitleMatchMode, 2 ; approximate match
for x in ComObjCreate("Shell.Application").Windows {
{
MsgBox,,Open Windows, % "`n" x.locationName "`n`n" x.locationURL "`n`n" x.FullName "`n"
winactivate, % x.locationName
sleep, 1000
WinMaximize, % x.locationName
sleep, 1000
; do something here
}
}
return
Hth,