Up/Down Key not working in Onenote 2016 for Autohotkey

Viewed 1809

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?

7 Answers

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}

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).

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

@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 )
}
Related