游戏开发论坛

 找回密码
 立即注册
搜索
查看: 3885|回复: 4

如何处理DirectInput独占模式下的中文输入问题?

[复制链接]

6

主题

24

帖子

36

积分

注册会员

Rank: 2

积分
36
发表于 2007-3-8 10:04:00 | 显示全部楼层 |阅读模式
当程序以独占级别初始化了DirectInput,程序将收不到任何的KEYDOWN消息。这时虽然可以通过命令打开中文输入法,但却无法输入任何文字,似乎是因为输入法也收不到键盘消息。
现在能想到的解决方法就是在程序进入中文输入状态时,临时释放键盘,在输入完成后再获取键盘独占权。

不知道各位高人有什么更好的方法,谢谢。

119

主题

1367

帖子

1393

积分

金牌会员

Rank: 6Rank: 6

积分
1393
发表于 2007-3-8 13:17:00 | 显示全部楼层

Re:如何处理DirectInput独占模式下的中文输入问题?

采用假全屏方式吧
独占模式渲染fps提高不了什么,现在大多游戏都采用假全屏,输入法的问题就迎刃而解了

15

主题

363

帖子

390

积分

中级会员

Rank: 3Rank: 3

积分
390
发表于 2007-3-8 14:47:00 | 显示全部楼层

Re:如何处理DirectInput独占模式下的中文输入问题?

楼上的是一个比较普遍的解法
不用DI就是最好的手段~
一般游戏是不必要用DI的,DI主要是为了那些对设备相应时间要求很高的程序才用的——比如格斗。

6

主题

24

帖子

36

积分

注册会员

Rank: 2

积分
36
 楼主| 发表于 2007-3-8 17:09:00 | 显示全部楼层

Re:如何处理DirectInput独占模式下的中文输入问题?

楼上两位所言极是。

有时候真的不必在一些无关紧要的问题上花太多时间,之前的想法是非用独占模式不可,其实并不是非常必要的。

谢谢

6

主题

24

帖子

36

积分

注册会员

Rank: 2

积分
36
 楼主| 发表于 2007-3-9 11:36:00 | 显示全部楼层

Re:如何处理DirectInput独占模式下的中文输入问题?

在键盘非独占模式下,按下键盘时,在程序收到WM_KEYDOWN消息,还将收到WM_CHAR消息,得到按键对应的字符,包括Backspace等一些非显示字符。这下所有文字输入问题都不再使用DirectInput了。

但没有使用独占模式,按键时,系统自动产生很多没有用的消息,虽然对程序的运行效率没有多大影响,可心里总是觉得不太舒服,而且非独占模式下,所有的windows热键都是有效的,我不希望这样。

今天突然想到,是否可以使用ImmSetCompositionString函数来实现文字编码的输入。
有没有人研究过?讨论一下吧,这个函数我还不太会用,也没有找到实例。

MSDN的说明是这样的,请高人解释一下:

The ImmSetCompositionString function sets the characters, attributes, and clauses of the composition and reading strings.

BOOL ImmSetCompositionString(
  HIMC hIMC,        
  DWORD dwIndex,   
  LPVOID lpComp,   
  DWORD dwCompLen,  
  LPVOID lpRead,   
  DWORD dwReadLen   
);

Parameters

hIMC
[in] Handle to the input context.

dwIndex
[in] Specifies the type of information to set. This parameter can be one of the following values. Value Meaning

SCS_SETSTR Sets the composition string, the reading string, or both. At least one of the lpComp and lpRead parameters must point to a valid string. If either string is too long, the IME truncates it.
SCS_CHANGEATTR Sets attributes for the composition string, the reading string, or both. At least one of the lpComp and lpRead parameters must point to a valid attribute array.  
SCS_CHANGECLAUSE Sets the clause information for the composition string, the reading string, or both. At least one of the lpComp and lpRead parameters must point to a valid clause information array.
SCS_SETRECONVERTSTRING Windows 98/Me, Windows 2000/XP: Asks IME to reconvert the string by a specified RECONVERTSTRING structure.
SCS_QUERYRECONVERTSTRING Windows 98/Me, Windows 2000/XP: Asks IME to adjust the RECONVERTSTRING structure. Then the application can pass the adjusted RECONVERTSTRING structure into this API with SCS_SETRECONVERTSTRING. IME will not generate any WM_IME_COMPOSITION messages.


lpComp
[in] Pointer to a buffer containing the information to set for the composition string. The information is as specified by the dwIndex value.

dwCompLen
[in] Specifies the size, in bytes, of the information buffer for the composition string. This is true even if SCS_SETSTR is specified and the buffer contains a Unicode string.

lpRead
[in] Pointer to a buffer containing the information to set for the reading string. The information is as specified by the dwIndex value.

dwReadLen
[in] Specifies the size, in bytes, of the information buffer for the reading string. The size is in bytes even if SCS_SETSTR is specified and the buffer contains a Unicode string.
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2026-1-26 16:59

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表