以编程方式启动Windows 10 Emoji热键 [英] Programmatically Launching Windows 10 Emoji Hotkeys
问题描述
Windows 10的最新主要更新"Fall Creators Update"(AKA RedStone3)具有
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.
我所做的就是创建一个新的小型WPF应用程序,其中一个主窗口包含一个TextBox和一个按钮.按下按钮将运行以下代码:
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);
这似乎没有影响!我还尝试了OEM_1(即:;"键代码)而不是OEM_PERIOD,但还是没有运气.关键是,LWIN与其他键(例如VK_P)的任何其他组合都可以与同一模拟器的代码一起使用.
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.
如果我尝试在真正的键盘上按Emoji热键,则在运行该代码后,第一次按不执行任何操作(有时Emoji弹出窗口显示半秒钟,然后立即消失),然后需要按该热键再次显示弹出窗口.这使我怀疑弹出窗口是否仅在屏幕范围之外才显示,或者是否正在等待另一个键盘事件发生/结束?
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?
推荐答案
在Windows Forms或WPF应用程序中打开Emoji面板
您需要处理所需的事件,然后首先 CoreInputView.GetForCurrentView
获取当前窗口的核心输入视图,然后调用其
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.
以Windows窗体或WPF调用Windows运行时API
.NET 5
-
解决方案资源管理器→右键单击您的项目→选择编辑项目文件".
Solution Explorer → Right click on your project → Choose Edit Project File.
将 TargetFramework
的值更改为以下字符串之一并保存更改.
Change the value of TargetFramework
to one of the following strings and save changes.
-
net5.0-windows10.0.17763.0
:用于定位Windows 10版本1809. -
net5.0-windows10.0.18362.0
:用于定位Windows 10版本1903. -
net5.0-windows10.0.19041.0
:用于定位Windows 10版本2004.
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.
例如:
<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
-
工具→NuGet软件包管理器→软件包管理器设置→确保为默认软件包管理格式选择了 PackageReference .
解决方案资源管理器→右键单击您的项目→选择管理NuGet软件包".
Solution Explorer → Right click on your project → choose Manage NuGet Packages.
找到 Microsoft.Windows.SDK.Contracts
程序包.在"NuGet软件包管理器"窗口的右窗格中,根据要定位的Windows 10版本,选择所需的软件包版本,然后单击安装":
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
:用于定位Windows 10版本2004. -
10.0.18362.xxxx
:用于定位Windows 10版本1903. -
10.0.17763.xxxx
:用于定位Windows 10版本1809. -
10.0.17134.xxxx
:用于定位Windows 10版本1803.
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.
这篇关于以编程方式启动Windows 10 Emoji热键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!