14

I mapped alt+i/k to Up/down key using Autohotkey, with the following code:

!i:: Send {up}
!k:: Send {down}

These remappings work with every application except Onenote 2016. I checked it online and found some discussions in the following links:

https://autohotkey.com/board/topic/15307-up-and-down-hotkeys-not-working-for-onenote-2007/

https://autohotkey.com/board/topic/41454-remap-key-doesnt-work-in-ms-onenote/

They suggest to use sendplay or sendraw, but these didn't work for me. Can anyone help me with this?

Jason
  • 1,200
  • 1
  • 10
  • 25

7 Answers7

8

It works if you use SendPlay and run AHK script with UI Access

This is your script with Send changed to SendPlay:

!i::SendPlay {up}
!k::SendPlay {down}

It emulates and as you expect. Tested with OneNote 2016 on Windows 10.

How to enable SendPlay: (which initially does nothing in Windows 10)

  1. Save the above mappings into AHK file. I used file updown.ahk with only these two lines.

  2. Right-click the above AHK file and from its context menu, select Run with UI Access (this actually does the trick)

Troubleshooting:

  • The item Run with UI Access is missing from context menu of AHK file

    1. Make sure your AutoHotKey is installed using the installer into Program Files directory. AutoHotKey documentation says UIA is only effective if the file is in a trusted location i.e. a Program Files sub-directory.

    2. In installer options, be sure to check the last item as shown below.  
      enter image description here

    Tip: if your AutoHotKey is already installed, it is sufficient just to re-run the installer (Installer.ahk found in location of AutoHotKey executables) and check the option. (No need to uninstall and install anew.)

  • SendPlay still does not work?

    1. See the FAQ topic How do I work around problems caused by User Account Control (UAC) available either online or inside local AHK help file. (They are the same.)

    2. Similar topic also describing limitations is Run with UI Access (available online or in local help).

miroxlav
  • 11,796
  • 5
  • 58
  • 99
  • Hi, thanks for your help! This remapping will jump between paragraphs and I want to jump between lines... – Jason Jun 02 '17 at 20:41
  • 1
    @Jason – finally, I solved the entire problem. Now it jumps between the lines as your expected. See the edited answer. Now Alt+I and Alt+K act as up and down arrow. – miroxlav Jun 03 '17 at 04:20
  • Wonderful! This problem has bothered me for a long time and you are my hero! – Jason Jun 03 '17 at 14:33
3

It seems that Autohotkey has issues with OneNote. Doing some trial and error I found that doing:

Send {CTRL DOWN}{UP}{CTRL UP}

simulates the up key but not completely.

R. Schifini
  • 9,085
  • 2
  • 26
  • 32
2

It seems that many have had problems with OneNote.

https://autohotkey.com/boards/viewtopic.php?f=5&t=25925

https://autohotkey.com/board/topic/49216-interference-between-microsoft-onenote-and-autohotkey/

However, some have suggested that having AHK open before running the Onenote resolves this problem. Surface Pro users don't seem to have any problems regarding AHK interacting with Onenote. May I ask what computer you use?

Hope it helps!

S.L
  • 183
  • 2
  • 12
  • @Jason did it help at all? – S.L Jun 02 '17 at 18:53
  • Um... "I know of no scenario where AHK didn't work with something because it was launched before the program was started"- exactly what I am saying and suggesting the OP to do... – S.L Jun 02 '17 at 19:08
  • My AHK is always running, and I don't see any differences using onenote. I have a surface pro 4 and the bugs are the same on that surface.... – Jason Jun 02 '17 at 20:33
  • Oh well... sorry for not being able to help – S.L Jun 02 '17 at 20:35
  • @ShawnLi and Jason: Perhaps you are both right. OneNote 2016 is a desktop application while OneNote is the Metro version. They are different and behave differently with AHK. – PGilm Jun 14 '18 at 21:25
2

My solution:

if (winactive("ahk_exe onenote.exe"))
{
    vk_code = 0xA0
    dllcall("keybd_event","UChar", vk_code, "UChar", 0, "UInt", 0, "Ptr", 0 )
    vk_code = 0x26
    dllcall("keybd_event","UChar", vk_code, "UChar", 0, "UInt", 0, "Ptr", 0 )
    vk_code = 0x26
    dllcall("keybd_event","UChar", vk_code, "UChar", 0, "UInt", 0x0002, "Ptr", 0 )
    vk_code = 0xA0
    dllcall("keybd_event","UChar", vk_code, "UChar", 0, "UInt", 0x0002, "Ptr", 0 )
}
else
    send  {blind}{up}
guest
  • 21
  • 1
2

Simplest way.

!i::ControlSend, OneNote::DocumentCanvas1, {Up}, ahk_exe ONENOTE.EXE

Found on the ahk forums here (original) and here (citing original I think) . Verified working on Windows 10 1803 with OneNote 2016 (desktop version).

wgrant
  • 165
  • 8
  • this does not move the cursor up one line, it moves the focus of a container to the one above it – Diego Nov 04 '19 at 17:48
0

everyone I have solved this problem ,by the extra programs sendup.exe and senddown.exe made by others

down the senddown.exe and sendup.exe from here


https://github.com/idvorkin/Vim-Keybindings-For-Onenote/blob/master/sendDown.exe
#if WinActive("ahk_exe" "ONENOTE.EXE")
j(){
    run %A_ScriptDir%\sendDown.exe
}
k(){
    run %A_ScriptDir%\sendUp.exe
} 
NumLock & j::j()
return
NumLock & k::k()
return

You can download exe from here

Ryan Wang
  • 1
  • 2
  • I have completely solve this problem on onenote 2016 with ahk call the sendup.exe and senddown.exe by this good people senddown.exe down from this link https://github.com/idvorkin/Vim-Keybindings-For-Onenote/blob/master/sendDown.exe and sendup.exe down from this link https://github.com/idvorkin/Vim-Keybindings-For-Onenote/blob/master/sendUp.exe then call these two program to finish the work #if WinActive("ahk_exe" "ONENOTE.EXE") j(){ run %A_ScriptDir%\sendDown.exe } k(){ run %A_ScriptDir%\sendUp.exe } CapsLock & j::j() return CapsLock & k::k() return #if – Ryan Wang Jun 12 '22 at 07:14
0

@miroxlav's accepted answer works for me, but I am unhappy with the security implications.

@guest's suggestion to use dllcall("keybd_event"...) showed the way, but unnecessarily sent Shift+Up., and did not support modifying the keys you are mapping to up/down, so that you can do things like pressing shift + your-fake-up key to extend the selection.

Leading to the code below - basically only sending the virtual keycodes vk_up and vk_down up/down, but matching any modifiers using *a::...

#If GetKeyState("Capslock","T") && alternate_keyboard_layouts == ...
;; map CapsLock + A/S => up/down

*a::work_around_OneNote_problems("up")
*s::work_around_OneNote_problems("down")
;; ^^ uses * - all modifiers - so that can do shift+a to exend selection, etc.

#If

work_around_OneNote_problems(key_str)
{
    local

    if (! winactive("ahk_exe onenote.exe"))
        send  {blind}{%key_str%}

    vk_up := 0x26
    vk_down := 0x28

    if( key_str == "up" )
    {
        send_keybd_event_down(vk_up)
        send_keybd_event_up(vk_up)
    }
    else if( key_str == "down" )
    {
        send_keybd_event_down(vk_down)
        send_keybd_event_up(vk_down)
    }
    else {
        msgbox, work_around_OneNote_problems only for up/down, got: <<%key_str%>>
    }
}

send_keybd_event_down(vk_code)
{
    dllcall("keybd_event","UChar", vk_code, "UChar", 0, "UInt", 0, "Ptr", 0 )
}
send_keybd_event_up(vk_code)
{
    dllcall("keybd_event","UChar", vk_code, "UChar", 0, "UInt", 0x0002, "Ptr", 0 )
}
Krazy Glew
  • 7,210
  • 2
  • 49
  • 62