Use a VK_Packet as a Hotkey

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
agentclone8
Posts: 3
Joined: 24 Jul 2021, 02:04

Use a VK_Packet as a Hotkey

24 Jul 2021, 02:12

Is it possible for AutoHotkey to detect a VK_Packet as a hotkey? I'm using Microsoft's remote desktop app to connect to my pc from my iPad, but for some reason they decided to send all iPad keyboard inputs as Unicode via VK_packets. This makes it so keyboard shortcuts don't always work the way they should. So can I use AutoHotkey to detect these vk_packets and output normal keystrokes?
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: Use a VK_Packet as a Hotkey

24 Jul 2021, 04:49

I suppose that iPad keyboard layouts and Windows keyboard layouts do not correspond, so it makes sense for the app to pass through the actual characters that you enter rather than trying to map them to virtual keycodes that will then map back to characters.

A hotkey must consist of optional modifiers plus a single "suffix" key which can be identified by VK (in the range 0x01-0xFF) or SC (in the range 0x001-0x1FF) - not both. VK_PACKET events all have the same VK value (VK_PACKET) and have a character code in place of an actual scancode. They cannot be handled as hotkeys.

You may try a hotstring of the form :*?:●::, replacing with the character you want to detect. However, this allows the character to reach the active window, then tries to delete it with backspace.

To both suppress and capture VK_PACKET events while ignoring other types of character input, you may use InputHook. The following should show a single MsgBox with "☺".

Code: Select all

ih := InputHook("L0 V") ; No collection buffer, visible input.
ih.KeyOpt("{All}", "I") ; Ignore character input from all keys.
; VK_PACKET events are treated as having scancode=0.  In current versions,
; the 'I' option must be cleared from both vkE7 and sc000 for VK_PACKET.
ih.KeyOpt("{vkE7}{sc000}", "-I")
ih.KeyOpt("{vkE7}", "S") ; Suppress VK_PACKET events. To not suppress, remove this line.
ih.OnChar := Func("OnPacket")
ih.Start()

OnPacket(ih, char) {
    MsgBox % char
}

Send {U+263A}
Sleep 1000
ExitApp
It's unclear to me how you would activate key combinations via the iPad app, but I suppose the following might be sufficient:

Code: Select all

ih := InputHook("L0 V I2") ; No collection buffer, visible input, ignore SendLevel<2.
ih.KeyOpt("{All}", "I") ; Ignore character input from all keys.
; VK_PACKET events are treated as having scancode=0.  In current versions,
; the 'I' option must be cleared from both vkE7 and sc000 for VK_PACKET.
ih.KeyOpt("{vkE7}{sc000}", "-I")
ih.KeyOpt("{vkE7}", "S") ; Suppress VK_PACKET events.
ih.OnChar := Func("OnPacket")
ih.Start()

OnPacket(ih, char) {
    SendLevel 1
    Send {Blind}{Raw}%char%
}
This code should be used standalone or placed in the auto-execute section.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Use a VK_Packet as a Hotkey

24 Jul 2021, 04:59

Code: Select all

vkE7::ToolTip % A_ThisHotkey
is a stretch but u can try it. otherwise, try a msg monitor(which may not trigger for any app other than the script that set it up):

Code: Select all

OnMessage(WM_KEYDOWN := 0x0100, Func("WM_KEYDOWN"))
WM_KEYDOWN(wParam, lParam, msg, hwnd) {
	switch wParam
	{
	case 0xE7: ; VK_PACKET
		ToolTip % A_ThisFunc
	}
}
if that doesnt work, ull have to install global WH_GETMESSAGE hooks(write the DLL, figure out the IPC with the ahk script, do the injection, yadda yadda)
agentclone8
Posts: 3
Joined: 24 Jul 2021, 02:04

Re: Use a VK_Packet as a Hotkey

24 Jul 2021, 19:06

Thank you so much, Lexikos, that second one worked perfectly! Now I can video edit or use Blender from my iPad with Microsoft Remote Desktop! Hooray! :superhappy:
agentclone8
Posts: 3
Joined: 24 Jul 2021, 02:04

Re: Use a VK_Packet as a Hotkey

02 Dec 2021, 08:10

I just realized that the code I used before still has one issue: holding down a key on the ipad does not register as holding down a key on the computer. Is there a way to solve this too? Thanks!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: scriptor2016 and 275 guests