Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically Launching Windows 10 Emoji Hotkeys

The latest major update for Windows 10, "Fall Creators Update" (AKA RedStone3), has added the functionality of a system-wide emoji pop-up that can be used in any textbox.

I'm trying to make a program that would launch that same pop-up emoji window when clicking on a button. As suggested in another discussion about similar topic, I've tried to use the InputSimulator project. There are also other ways, as suggest here, but seems like that simulator is wrapping them pretty well.

All I did was to create a new small WPF application, with one main window which has a TextBox and a button. Pressing the button would run the following code:

textBox.Focus()
new InputSimulator().Keyboard.ModifiedKeyStroke(VirtualKeyCode.LWIN, VirtualKeyCode.OEM_PERIOD);

This seems to have no affect! I've also tried OEM_1 (which is the ":;" keycode) instead of OEM_PERIOD, but still no luck. The thing is, any other combination of LWIN with another key (such as VK_P) would work with the same simulator's code.

If I try to press the Emoji Hotkeys on the real keyboard, after running that code, the first press does nothing (sometimes the emoji pop-up shows for half a second and disappears right after) and then need to press the hotkeys again in order for the popup to show. This makes me suspect that maybe the popup does show, only outside of the screen bounds, or perhaps waiting for another keyboard event to happen/finish?

like image 205
Yoav Feuerstein Avatar asked Oct 26 '17 19:10

Yoav Feuerstein


People also ask

What is the shortcut to open emojis in Windows 10?

To use it: During text entry, type Windows logo key + . (period). The emoji keyboard will appear.

How do I enable emoji shortcuts?

Go to Settings > General and tap Keyboard. Tap Keyboards, then tap Add New Keyboard. Tap Emoji.

How do you open emoji keyboard?

In Microsoft apps such as Notepad or Word, or in the Edge web browser, press Windows key + ; (semicolon) or Windows key +. (period) to open a window that will allow you to insert an emoji, kaomoji or special character. For emojis, click on the smiley face and then on the category – People, Food and plants, etc.


1 Answers

Open Emoji panel in a Windows Forms or WPF application

You need to handle the desired event, then first Focus to your control, then using CoreInputView.GetForCurrentView get the core input view for the current window, and then call its TryShow method and pass CoreInputViewKind.Emoji to the method. For example:

//using Windows.UI.ViewManagement.Core;
private async void button1_Click(object sender, EventArgs e)
{
    textBox1.Focus();
    CoreInputView.GetForCurrentView().TryShow(CoreInputViewKind.Emoji);
}

Note: For Windows Forms or WPF project, before using above code, you need to configure your project to be able to call Windows Runtime APIs in desktop apps.

Call Windows Runtime APIs in Windows Forms or WPF

.NET 5

  1. Solution Explorer → Right click on your project → Choose Edit Project File.

  2. Change the value of TargetFramework to one of the following strings and save changes.

    • net5.0-windows10.0.17763.0: for targeting Windows 10, version 1809.
    • net5.0-windows10.0.18362.0: for targeting Windows 10, version 1903.
    • net5.0-windows10.0.19041.0: for targeting Windows 10, version 2004.

    For example:

    <Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
      <PropertyGroup>
        <OutputType>WinExe</OutputType>
        <TargetFramework>net5.0-windows10.0.18362.0</TargetFramework>
        <UseWindowsForms>true</UseWindowsForms>
      </PropertyGroup>
    </Project>
    

.NET 4.X

  1. Tools → NuGet Package Manager → Package Manager Settings → Make sure PackageReference is selected for Default package management format.

  2. Solution Explorer → Right click on your project → choose Manage NuGet Packages.

  3. Find Microsoft.Windows.SDK.Contracts package. In the right pane of the NuGet Package Manager window select the desired version of the package based on the version of Windows 10 you want to target and click install:

    • 10.0.19041.xxxx: for targeting Windows 10, version 2004.
    • 10.0.18362.xxxx: for targeting Windows 10, version 1903.
    • 10.0.17763.xxxx: for targeting Windows 10, version 1809.
    • 10.0.17134.xxxx: for targeting Windows 10, version 1803.
like image 79
Reza Aghaei Avatar answered Sep 29 '22 17:09

Reza Aghaei