1

I want to write a program that repeatedly writes a predefined text inside of another program.

It works pretty good right now but I need to let my program press the enter key on the main keyboard. This msdn documentary delivers only the key code for the enter key on the numpad which is 0x0D.

But I have to use the main keyboard's enter key and can't find the representative key code.

Does anyone know the correct key code?

Thanks for any help.

Aoki.Miku
  • 37
  • 1
  • 10
  • 6
    Aren’t they the same? – Ry- Jun 28 '19 at 14:48
  • 1
    Did you perform a Google search for this first? This type of information should be trivial to search for. – Daniel Mann Jun 28 '19 at 14:50
  • I'm only asking here because I didn't find the answer on Google. I found the mentioned msdn documentary and another list which is pretty the same. – Aoki.Miku Jun 28 '19 at 14:52
  • 2
    The documentation you linked to does not provide/show the keycode specifically for the Enter key on the Numpad. It just lists the keycode for the Enter key. Period. No mention of Numpad Enter anywhere. Also, i second the 1st comment... –  Jun 28 '19 at 14:53
  • 1
    I would have guessed too that they are got the same key codes but the external program does not accept the numpad's enter, only the main keyboard's. – Aoki.Miku Jun 28 '19 at 14:54
  • @elgonzo I know, but after some testing I noticed that this has to be the numpad's enter key. – Aoki.Miku Jun 28 '19 at 14:56
  • There are no differen keycodes for Enter vs. Numpad Enter. Both the same. Whatever the other program is doing, it is not specifically related to key codes. Perhaps it interprets keyboard input/events creatively, perhaps it sniffs scan codes, perhaps there is some other side effect. .Who knows... –  Jun 28 '19 at 14:56
  • This seems to be a duplicate of https://stackoverflow.com/questions/5989380/sending-specific-keys-on-the-numpad-like-or-enter-simulating-a-keypress – bkqc Jun 28 '19 at 14:57
  • There *is* a difference, but it's not in the key code. The [`WM_KEYDOWN`](https://learn.microsoft.com/windows/desktop/inputdev/wm-keydown) message will have bit 24 set in the `lParam` for a numpad Enter keypress; C# does not directly surface this. – Jeroen Mostert Jun 28 '19 at 15:01
  • @JeroenMostert Thank you! That's some kind of information I can work with. Did I understand you correctly that there is no way to unset bit 24 to simulate a non-numpad enter in C#? – Aoki.Miku Jun 28 '19 at 15:08
  • No -- I would not expect a C# generated keypress to actually set bit 24, that would be weird. Some code for a repro would be handy. – Jeroen Mostert Jun 28 '19 at 15:09
  • @JeroenMostert Maybe this will get too offtopic and I should start a new question about that. – Aoki.Miku Jun 28 '19 at 15:13

2 Answers2

1

You can simulate pressing enter by using SendKeys.Send("{ENTER}"); which might not be the exact way you hoped to do it. If 0x0D isnt working, (see @Margus' answer), I encourage you to try this.

SJ10
  • 315
  • 1
  • 4
  • 12
  • This might not be the exact "simulation" that you are thinking of, but this seems to be processed the way you need in the applications I have used it for. – SJ10 Jun 28 '19 at 15:26
0

They are the same.

VK_RETURN 0x0D ENTER key

source: https://learn.microsoft.com/en-us/windows/desktop/inputdev/virtual-key-codes

Margus
  • 19,694
  • 14
  • 55
  • 103