我正在使用需要将击键发送到第三方应用程序的屏幕键盘。它们在 Windows XP 上运行。需要支持美国英语键盘上不可用的一小组字符(例如“\xc3\xa5”或\xc3\xb1)。在查看 SendInput 后,似乎最安全的事情是将字符的十六进制 unicode 值作为击键序列发送。我编写的代码发送“Alt”和“Add”按键按下事件,然后发送与 Alt 键 ORed 的四字符 unicode 序列的按键按下和向上事件,最后发送“Add”和“Alt”按键按下事件。在我的 C# 测试应用程序中。我正在使用 KeyPreview,果然,所有事件都会通过,但我得到的只是一声蜂鸣声,没有字符。我通过手动输入击键捕获了相同的信息,KeyPreview 信息相同,并且出现了字符。
\n\n可以这样使用SendInput吗?我没有使用钩子来检查数据,但我看到帖子表明 SendInput 事件附加了某种“注入”标志,也许这会导致序列失败?
\n\n此演示代码成功发送按键事件,但旨在生成 unicode 字符的一系列按键事件失败。
\n\n private const uint KEYEVENTF_KEYDOWN = 0x0000;\n private const uint KEYEVENTF_EXTENDEDKEY = 0x0001;\n private const uint KEYEVENTF_KEYUP = 0x0002;\n\n private const int INPUT_KEYBOARD = 1;\n\n [DllImport ("user32.dll", SetLastError = false)]\n static extern IntPtr GetMessageExtraInfo ();\n\n [DllImport ("user32.dll", SetLastError = true)]\n static extern uint SendInput (uint nInputs, [MarshalAs (UnmanagedType.LPArray, SizeConst = 1)] INPUT[] pInputs, int …Run Code Online (Sandbox Code Playgroud) 如果我想在 editText 中输入消息,我输入一些数字,我的键盘如下所示:

但在我通过单击按钮 ( et.setText(et.getText().toString() + " " + "abc")) 从代码添加一些文本后,键盘更改为:

有办法防止这种情况发生吗?
大家好,我试图获取键盘输入附件视图的 y 位置,如下所示:
-(void)textViewDidBeginEditing:(UITextView *)textView
{
ipvFrame = textView.inputAccessoryView.frame;
}
-(void)textViewDidChange:(UITextView *)textView
{
NSLog(@"Input Accessory View:%f",ipvFrame.origin.y);
}
Run Code Online (Sandbox Code Playgroud)
然而 NSLog 说 ipvFrame y 位置是 0!有人知道为什么吗?
到目前为止我的代码如下:
\n\nimport javax.swing.JFrame;\nimport javax.swing.JButton;\nimport javax.swing.JPanel;\nimport java.awt.GridLayout;\nimport java.awt.FlowLayout;\n\npublic class GUI extends JFrame\n{\n private JButton button;\n private JPanel panel;\n private static final String[][] key = { { "Esc", "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12", "PrtSc", "Insert", "Delete", "Home", "End", "PgUp", "PgDn"}, { "3\\n2", "&", "\xc3\xa9", "\\"", "\'", "(", "\xc2\xa7", "\xc3\xa8", "!", "\xc3\xa7", "\xc3\xa0", ")", "-", "BkSpc", "NumLock", "/", "*", "-" }, { "Tab", "A", "Z", "E", "R", "T", "Y", "U", "I", "O", "P", "^", "$", …Run Code Online (Sandbox Code Playgroud) 有谁知道如何检测用户何时更改 OSX 中的当前输入源?

我可以调用TISCopyCurrentKeyboardInputSource()来找出正在使用哪个输入源 ID,如下所示:
TISInputSourceRef isource = TISCopyCurrentKeyboardInputSource();
if ( isource == NULL )
{
cerr << "Couldn't get the current input source\n.";
return -1;
}
CFStringRef id = (CFStringRef)TISGetInputSourceProperty(
isource,
kTISPropertyInputSourceID);
CFRelease(isource);
Run Code Online (Sandbox Code Playgroud)
如果我的输入源是“德语”,那么 id 最终会是“com.apple.keylayout.German”,这主要是我想要的。除了:
TISCopyCurrentKeyboardInputSource()不会改变吗?特别是,我可以TISCopyCurrentKeyboardInputSource()循环调用并切换输入源,但TISCopyCurrentKeyboardInputSource()不断返回进程开始时的输入源。我有以下代码将 eventListener 添加到 HTML textarea。它应该控制台记录按下的键码,并且,如果键码是 == 到 17 (CTRL),则控制台记录“您按下了 CTRL。”。出于某种原因,当我在 textarea 中按下 CTRL 时,它不是控制台记录按下的 keyCode,也不是“你按下了 CTRL”。例如,如果我按“A”,控制台日志返回“97”,这是正确的。它也适用于所有其他字母。
这是代码:
document.getElementById("msgBox").addEventListener("keypress",function(e){
console.log(e.keyCode);
if(e.keyCode == 17){
console.log("You pressed CTRL.");
}
});
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
更新:它也不适用于其他特殊键,如“shift、Fx、alt、home 等。
文本区域的 HTML :
<textarea id="msgBox" placeholder="Enter your message" autofocus></textarea>
Run Code Online (Sandbox Code Playgroud) 我想将数字锁定按钮用于数字锁定以外的其他用途。所以基本上我想在按下数字锁定键时关闭它并保持关闭状态。我可以捕获按钮按下的情况,但它仍然会打开/关闭。我总是想把它关掉。有什么建议么?
不确定为什么有人想知道为什么我想这样做,但原因如下:我有一个蓝牙数字键盘,我想用它来控制机器。这是否证明了这个问题的合理性?
经过几个小时的研究,我发现了以下代码,它达到了目的:
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
class SetNumlockKeyOn
{
[StructLayout(LayoutKind.Sequential)]
public struct INPUT
{
internal int type;
internal short wVk;
internal short wScan;
internal int dwFlags;
internal int time;
internal IntPtr dwExtraInfo;
int dummy1;
int dummy2;
internal int type1;
internal short wVk1;
internal short wScan1;
internal int dwFlags1;
internal int time1;
internal IntPtr dwExtraInfo1;
int dummy3;
int dummy4;
}
[DllImport("user32.dll")]
static extern int SendInput(uint nInputs, IntPtr pInputs, int cbSize);
public static void SetNumlockOn()
{
if (Control.IsKeyLocked(Keys.NumLock)) return; …Run Code Online (Sandbox Code Playgroud) using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Diagnostics;
// The application can disable windows key task manager and ctrl esc etc
namespace TrialLocks
{
public partial class Form1 : Form
{
[DllImport("user32", EntryPoint = "SetWindowsHookExA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern int SetWindowsHookEx(int idHook, LowLevelKeyboardProcDelegate lpfn, int hMod, int dwThreadId);
[DllImport("user32", EntryPoint = "UnhookWindowsHookEx", CharSet = CharSet.Ansi, SetLastError = true, …Run Code Online (Sandbox Code Playgroud) 在运行 Ubuntu 18.04 时,我的笔记本电脑上的键盘随机开始表现得很奇怪。这包括:
奇怪的是,虽然发生这种情况,但外接键盘继续正常工作。另外,我在运行 Windows 时不会遇到这个问题。
我正在 codeandbox.io 上学习 React,它与我目前的主要代码编辑器 VSCode 完全一样。
但是,我找不到注释和取消注释代码行的快捷方式,这对我来说非常令人沮丧。
在 VSCode 中注释代码的键盘快捷键是CMD + Shift + 7(在西班牙语键盘中),但它在 codeandbox.io 中不起作用。我认为英文键盘的快捷键只是CMD + /
keyboard ×10
c# ×3
android ×1
cocoa ×1
codesandbox ×1
dom-events ×1
flowlayout ×1
grid-layout ×1
hook ×1
ios ×1
iphone ×1
java ×1
javascript ×1
keycode ×1
localization ×1
macos ×1
macos-carbon ×1
shortcut ×1
swing ×1
ubuntu-18.04 ×1
unicode ×1