1

Dear coding enthusiasts,

In the last year I got to know the remarkable commandline tool NirCmd. With that I realized many functions on a single shortcut such as muting microphone, setting volume to predefined level, and many more. So when I need to talk via teams I can control all my sound options with any keyboard and the notebook closed. What I did not yet realize is to answer and incoming MS Teams call. NirCmd has the option to identify windows reliably.

For testing purpose I have a word file named test.docx open. When it is in the background, this NirCmd call via desktop shortcut activates it properly: nircmd.exe win activate ititle "test" So the ititle works.

No, again to test the basic principle I want to send a keystroke to the test.docx window, without activating it. It shall remain in the background.

What I have found while searching stackoverflow and other sites "[…] as Sendmsg will talk to the win api, IIRC to send keystrokes you need 0x102 and wparam the dec ascii val lower case e being 101. So try nircmd win sendmsg ititle "gamename" 0x102 101 1 – user6811411" "# send a Return to that window (0x102 is WM_CHAR and 0x0D is VK_ENTER)"

So I suspected my NirCmd call must look like this: nircmd.exe win sendmsg ititle "test" 0x102 0x0D 0

But unfortunately nothing happens. I worked on it the whole morning, searching the web endlessly, but I do not get through it. Is there anyone that can shed some light on how I can send an 'enter' keystroke to a word window in the background determined via 'ititle'?

Many thanks in advance! Best regards, Andreas

  • [You can't simulate keyboard input with PostMessage](https://devblogs.microsoft.com/oldnewthing/20050530-11/?p=35513). – IInspectable Jun 14 '21 at 12:48
  • In case you are wondering, Word has an [automation API](https://learn.microsoft.com/en-us/office/vba/api/overview/word/object-model) so you don't have to fake input (and fail in the process of doing). – IInspectable Jun 14 '21 at 20:09
  • Dear Iinspectable, thank you for your answers. I did solve my problem with a workaround. I found out that the 'script' function within NirCmd is faster than executing two subsequent commands via vbs. Therefore I firstly select the desired window with one NirCmd line and secondly shoot via SendKeyPress the respective key combination. Both lines in a ncl file. So a result is achieved. It was very kind that you had a look at my request and gave me a direction what to furhter pursue and what not. Greetings, Andreas – Andreas Hanisch Jun 16 '21 at 08:00
  • Andreas, can you provide those two lines that worked, please? – Steve3p0 Jan 24 '23 at 13:50

0 Answers0