obsidian-notes/代码/响应按键输入.md
CSSC-WORK\murmur 3e6078442b init version
2024-04-15 11:19:57 +08:00

32 lines
1.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: 响应按键输入
updated: 2022-01-20 03:20:40Z
created: 2022-01-20 02:51:56Z
---
`ctrl.wndproc = function(hwnd,message,wParam,lParam){}`
处理控件的消息回调
# 输入法的影响
中文输入法会影响条件判断,在不需要的场合要进行屏蔽,可以通过`key.capsLk()`屏蔽,
或`key.ime.setOpenStatus(0)//避免输入法干扰`
==最优解可能是==`ctrl.disableInputMethod()`基于edit控件的都支持
```js
disableInputMethod = function(){
::Imm32 := ..raw.loadDll("Imm32.dll");
var imc = ::Imm32.ImmGetContext(owner.hwnd);
if (imc) {
::Imm32.ImmAssociateContext(owner.hwnd,null);
::Imm32.ImmReleaseContext(owner.hwnd,imc);
}
};
```
以上方法可配合`message == 0x102/*_WM_CHAR*/`对输入字符进行过滤
[编辑框数据有效性判断](编辑框数据有效性判断.md) 中编辑框激活后屏蔽中文等非eng输入法以避免非法字符的输入
# 字符类
`message == 0x102/*_WM_CHAR*/`只能过滤==CHAR==,对控制类、功能类按键无效,
# 非字符类
此类按键的过滤需要使用`message == 0x101/*_WM_KEYUP*/`,即==按键消息==。
# 非按键输入
通过鼠标等的输入无法通过按键捕获,需要额外处理