Emulate keyboard keys through Vim that the OS interpret it.

8 views
Skip to first unread message

Nicolas

unread,
Nov 12, 2022, 6:05:06 AM11/12/22
to vim_use
Is it possible to emulate keyboard keys through Vim Editor so that the OS interprets them?

example: Is is possible to emulate Windows Key(VK_LWIN)+R keys?

VK_LWIN as defined here
https://learn.microsoft.com/fr-fr/windows/win32/inputdev/virtual-key-codes


Thanks
Nicholas

Enan Ajmain

unread,
Nov 12, 2022, 6:39:39 AM11/12/22
to vim...@googlegroups.com
On Sat, 12 Nov 2022 03:05:06 -0800 (PST)
Nicolas <niva...@gmail.com> wrote:
> Is it possible to emulate keyboard keys through Vim Editor so that
> the OS interprets them?
>

Vim sits on _top_ of OS, so it's unlikely that Vim can modify a keypress
event and send it to OS. That would require Vim to sit in the _middle_
of the keypress event and the OS.

I'm doubtful you want that, though. You probably want to map a key in
Vim. This assumption is supported by your example.

> example: Is is possible to emulate Windows Key(VK_LWIN)+R keys?

Vim cannot map Windows keys. But you can look through online help sites,
e.g., vi.stackexchange.com, to see if anyone has come up with a
workaround.

Here is a possible solution: https://stackoverflow.com/q/327415/11135136

--
Enan
3nan....@gmail.com
https://www.github.com/3N4N

GPG Key ID: 448F8D0D0D6DB601566E396CA031EA10A3ECB75D

Stan Brown

unread,
Nov 12, 2022, 11:18:00 AM11/12/22
to vim...@googlegroups.com
The interpretation of keys goes in the other direction: first Windows
interprets a keypress, then it passes on the possibly-remapped key to
Vim or whatever other application has focus, and _that_ application
interprets what it got from Windows.

But Windows+R is just the Run command, so you could emulate it by the :!
command in Vim.

There are some differences in the implementation details between :! and
Windows+R, so if you really want to you could use the excellent and free
Autohotkey <https://www.autohotkey.com/> to sense when you press :! (or
any other chosen combination) in a Vim window and pass Widows+R to the OS.

Stan Brown
Tehachapi, CA, USA
https://BrownMath.com
Reply all
Reply to author
Forward
0 new messages