以编程方式启动 Windows 10 个表情符号热键
Programmatically Launching Windows 10 Emoji Hotkeys
Windows 10 的最新主要更新 "Fall Creators Update"(又名 RedStone3)具有可用于任何文本框的 added the functionality of a system-wide emoji pop-up。
我正在尝试制作一个程序,在单击按钮时会启动相同的弹出表情符号 window。正如 another discussion about similar topic, I've tried to use the InputSimulator project. There are also other ways, as suggest here 中所建议的那样,但似乎模拟器将它们包装得很好。
我所做的只是创建一个新的小型 WPF 应用程序,其中一个主要 window 有一个文本框和一个按钮。按下按钮将 运行 以下代码:
textBox.Focus()
new InputSimulator().Keyboard.ModifiedKeyStroke(VirtualKeyCode.LWIN, VirtualKeyCode.OEM_PERIOD);
这个好像没什么影响!我也试过 OEM_1(这是“:;”键码)而不是 OEM_PERIOD,但仍然没有成功。问题是,LWIN 与另一个键(例如 VK_P)的任何其他组合都可以使用相同的模拟器代码。
如果我尝试按真实键盘上的表情符号热键,在 运行 执行该代码后,第一次按下时什么都不做(有时表情符号弹出窗口会显示半秒钟,然后立即消失)然后需要再次按下热键才能显示弹出窗口。这让我怀疑弹出窗口可能确实显示,只是在屏幕边界之外,或者可能正在等待另一个键盘事件 happen/finish?
在 Windows 表单或 WPF 应用程序中打开表情符号面板
您需要处理所需的事件,然后先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
到方法。例如:
//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
解决方案资源管理器 → 右键单击您的项目 → 选择编辑项目文件。
将 TargetFramework
的值更改为以下字符串之一并保存更改。
net5.0-windows10.0.17763.0
:针对 Windows10,版本 1809。
net5.0-windows10.0.18362.0
:针对 Windows10,版本 1903。
net5.0-windows10.0.19041.0
:针对 Windows10,版本 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 被 selected 用于 默认包管理格式 .
解决方案资源管理器 → 右键单击您的项目 → 选择管理 NuGet 包。
找到 Microsoft.Windows.SDK.Contracts
包。在 NuGet 包管理器 window select 的右侧窗格中,根据要定位的 Windows 10 版本选择所需的包版本,然后单击安装:
10.0.19041.xxxx
:针对 Windows10,版本 2004。
10.0.18362.xxxx
:针对 Windows10,版本 1903。
10.0.17763.xxxx
:针对 Windows10,版本 1809。
10.0.17134.xxxx
:针对 Windows10,版本 1803。
由于无法让这些更优雅的解决方案发挥作用,我求助于键盘调用。这非常适合我的需要,所以我想我会分享。
Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As IntPtr, ByVal bScan As IntPtr, ByVal dwFlags As IntPtr, ByVal dwExtraInfo As IntPtr)
Private Sub EmojiLaunch_Click(sender As Object, e As EventArgs) Handles EmojiLaunch.Click
Call keybd_event(&H5B, 0, &H0, 0) 'Windows Key Down
Call keybd_event(&HBE, 0, &H0, 0) 'Period Key Down
Call keybd_event(&HBE, 0, &H2, 0) 'Period Key Up
Call keybd_event(&H5B, 0, &H2, 0) 'Windows Key Up
End Sub
EmojiLaunch 是一个标签,您不想使用按钮,因为它会改变焦点。
Windows 10 的最新主要更新 "Fall Creators Update"(又名 RedStone3)具有可用于任何文本框的 added the functionality of a system-wide emoji pop-up。
我正在尝试制作一个程序,在单击按钮时会启动相同的弹出表情符号 window。正如 another discussion about similar topic, I've tried to use the InputSimulator project. There are also other ways, as suggest here 中所建议的那样,但似乎模拟器将它们包装得很好。
我所做的只是创建一个新的小型 WPF 应用程序,其中一个主要 window 有一个文本框和一个按钮。按下按钮将 运行 以下代码:
textBox.Focus()
new InputSimulator().Keyboard.ModifiedKeyStroke(VirtualKeyCode.LWIN, VirtualKeyCode.OEM_PERIOD);
这个好像没什么影响!我也试过 OEM_1(这是“:;”键码)而不是 OEM_PERIOD,但仍然没有成功。问题是,LWIN 与另一个键(例如 VK_P)的任何其他组合都可以使用相同的模拟器代码。
如果我尝试按真实键盘上的表情符号热键,在 运行 执行该代码后,第一次按下时什么都不做(有时表情符号弹出窗口会显示半秒钟,然后立即消失)然后需要再次按下热键才能显示弹出窗口。这让我怀疑弹出窗口可能确实显示,只是在屏幕边界之外,或者可能正在等待另一个键盘事件 happen/finish?
在 Windows 表单或 WPF 应用程序中打开表情符号面板
您需要处理所需的事件,然后先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
到方法。例如:
//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
解决方案资源管理器 → 右键单击您的项目 → 选择编辑项目文件。
将
TargetFramework
的值更改为以下字符串之一并保存更改。net5.0-windows10.0.17763.0
:针对 Windows10,版本 1809。net5.0-windows10.0.18362.0
:针对 Windows10,版本 1903。net5.0-windows10.0.19041.0
:针对 Windows10,版本 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 被 selected 用于 默认包管理格式 .
解决方案资源管理器 → 右键单击您的项目 → 选择管理 NuGet 包。
找到
Microsoft.Windows.SDK.Contracts
包。在 NuGet 包管理器 window select 的右侧窗格中,根据要定位的 Windows 10 版本选择所需的包版本,然后单击安装:10.0.19041.xxxx
:针对 Windows10,版本 2004。10.0.18362.xxxx
:针对 Windows10,版本 1903。10.0.17763.xxxx
:针对 Windows10,版本 1809。10.0.17134.xxxx
:针对 Windows10,版本 1803。
由于无法让这些更优雅的解决方案发挥作用,我求助于键盘调用。这非常适合我的需要,所以我想我会分享。
Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As IntPtr, ByVal bScan As IntPtr, ByVal dwFlags As IntPtr, ByVal dwExtraInfo As IntPtr)
Private Sub EmojiLaunch_Click(sender As Object, e As EventArgs) Handles EmojiLaunch.Click
Call keybd_event(&H5B, 0, &H0, 0) 'Windows Key Down
Call keybd_event(&HBE, 0, &H0, 0) 'Period Key Down
Call keybd_event(&HBE, 0, &H2, 0) 'Period Key Up
Call keybd_event(&H5B, 0, &H2, 0) 'Windows Key Up
End Sub
EmojiLaunch 是一个标签,您不想使用按钮,因为它会改变焦点。