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

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

Related

Issues sending key events to browser window autohotkey

I am trying to open up a webpage and save it as a complete file. This should be a relatively easy task for autohotkey. For some reason my script is not sending key events to the window. Here's the script:
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn All, StdOut ; 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.
Run, www.google.com
WinWaitActive firefox.exe
sleep, 4000
ControlSend, ahk_class MozillaWindowClass, ^s
What would be a better approach to this problem?
Here is my solution:
Run, www.google.com
WinWaitActive ahk_exe firefox.exe
sleep, 4000
Send ^s
There were two main things that were changed for this to work
Include ahk_exe before the name of the exe in the WinWaitActive conditional
Removed the ControlSend and replaced it with a regular Send, since we are already waiting for the Window to be activated
Hope this helps, feel free to ask for any more clarification or help if you need it
ControlSend, ahk_parent, ^s, ahk_class MozillaWindowClass

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

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,

Fix Labview Alt-Tab behaviour with 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".

Hotkey causing variable to be unassigned?

I know I'm missing something obvious but I can't figure out why this doesn't work. Why doesn't hello show up in the first msgbox I know it says the variable isn't assigned if I uncomment #Warn? This is the only thing in the ahk 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.
#SingleInstance force
; Reload the script
^!z::
WinActivate, ahk_class Notepad++
Send {ctrl down}s{ctrl up}
sleep 100
Reload
return
ADPass = hello
!5::
MsgBox, %ADPass%
Msgbox, test
return
Your assignment of ADPass never gets executed because it is between 2 hotkeys. You must place it before you begin your hotkeys (before ^!z) or place it within your hotkey (!5) to ensure it is executed.
I think the other answer would probably work, you need the variable to be set before the return. The return means the machine is never getting to that line of code, Try this.
#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.
#SingleInstance force
ADPass = hello; this doesn't have to stay here, just make sure it's before the return.
; Reload the script
^!z::
WinActivate, ahk_class Notepad++
Send {ctrl down}s{ctrl up}
sleep 100
Reload
return
!5::
MsgBox, %ADPass%
Msgbox, test
return
or
#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.
#SingleInstance force
; Reload the script
^!z::
WinActivate, ahk_class Notepad++
Send {ctrl down}s{ctrl up}
sleep 100
Reload
return
!5::
goto set
point:
MsgBox, %ADPass%
Msgbox, test
return
set:
ADPass = hello
goto point
Return