1

I don't really know what I should type in the title, but anyway, here is what I need :

I make small programs that do stuff like, "typing" the given input. Here is a small example to type "test" (as example).

#include <windows.h>
void Press(int Touch);

int main()
{
    Sleep(5000);//Sleep a bit, so that you can select where to type
    Press(VkKeyScan('t'));
    Press(VkKeyScan('e'));
    Press(VkKeyScan('s'));
    Press(VkKeyScan('t'));

    return 0;
}

void Press(int Touch)
{
    keybd_event(Touch, 0x9d, 0, 0);
    keybd_event(Touch, 0x9d, KEYEVENTF_KEYUP, 0);
}

So what I need is barely this, but with emojis. I need to be able to "type" any emoji like this one : "", from my program. Any ideas please ?

Mr. Llama
  • 20,202
  • 2
  • 62
  • 115
Neox
  • 279
  • 3
  • 13
  • It is going to be much easier if you can use a graphic framework like Qt – Marco Oct 20 '15 at 19:21
  • It sounds like you're saying you want to programmatically simulate keyboard input. Are you hoping to inject the simulated keystrokes into the system itself, or do you only need to feed them to a userspace program? – John Bollinger Oct 20 '15 at 19:22
  • This isn't really an answer to your question, but [AutoHotkey](http://www.autohotkey.com/) is a really good tool for things like this if you're just looking to do this for yourself. – rlbond Oct 20 '15 at 19:22
  • @Marco : isn't there any other way ? These are small programs, I don't really want to add such stuff there. – Neox Oct 20 '15 at 19:23
  • @JohnBollinger : Yeah I want to "programmatically" simulate the keyboard input, but I don't think it's possible with emojis. So I'm searching another way to do it, but I don't know any. And I don't understand the second part of your question. – Neox Oct 20 '15 at 19:25
  • @rlbond : it is for myself yes, but I want to do it using C/C++. – Neox Oct 20 '15 at 19:26
  • Well emojis are graphics, unless you have an OS that fully support emojis you will have to use graphic tools, and Qt is big but not so much. – Marco Oct 20 '15 at 19:28
  • @Marco : Then I may use Qt for this, but... well, yeah, I will search but, do YOU have any idea of how I can do it using Qt ? Useful functions, etc ? Can you tell me all I need ? – Neox Oct 20 '15 at 19:29
  • 3
    @Marco - emoji are *not* graphics, they're [Unicode characters](https://en.wikipedia.org/wiki/Emoji#In_the_Unicode_standard) that happen to look like pictures. – Mr. Llama Oct 20 '15 at 19:31

2 Answers2

1

There's two ways you can approach this.

The first is using "alt codes":

  • Hold the ALT key
  • Press + on the number pad
  • Type the Unicode code point in hex
  • Release the ALT key

However, this method requires having EnableHexNumpad set in the Windows registry.

The second would be using the Windows clipboard.

  • Save the contents of the Windows clipboard
  • Set the clipboard contents to the Unicode character you wish to insert
  • Send CTRL + V to paste the character
  • Revert the clipboard to its previous content
Mr. Llama
  • 20,202
  • 2
  • 62
  • 115
  • That is really interesting, I didn't know about `EnableHexNumpad` (I already thought about sending Alt + [Code] stuff, but you can't get emojis from there), and I already thought about the clipboard but... as I'm a bit dumb, I never thought about recovering the previous content back ! Thanks for your answer ! But, I don't know if I should mark this as "Accepted answer" since it's not directly what I need, but kinda alternative methods. Anyway, thanks. – Neox Oct 20 '15 at 19:33
1

keybd_event is deprecated, as mentioned on its MSDN page. Usually when you look up a Windows function and it is deprecated, you really should consider using the newer one.

Use SendInput, which among other things supports unicode keyboard input emulation.

You can send non-16-bit clean unicode characters by packing two different INPUT structures in a row.

Yakk - Adam Nevraumont
  • 262,606
  • 27
  • 330
  • 524
  • Ok, I'll check this out. I saw a few things about this function, but as keybd_event works, I didn't really try to use it. – Neox Oct 20 '15 at 19:36