将字符转换为键盘码的代码
来源:互联网 发布:淘宝新规则2017 售假 编辑:程序博客网 时间:2024/06/10 02:10
以下这段代码可以将字符串转换为键盘码,以备需要时用到。
- (int)keyCodeForCharacter: (NSString*)character { if(![character length]) return -1; char code; BOOL shift, alt; if(Ascii2Virtual( (char)[character characterAtIndex: 0], &shift, &alt, &code)) {return code;} return -1;}
BOOL Ascii2Virtual(char pcar, BOOL *pshift, BOOL *palt, char *pkeycode){ KeyboardLayoutRef keyboard; const void *keyboardData; // keyboard layout data UInt16 nbblocs; char *modblocs, *blocs, *deadkeys; int ix, ifin, numbloc, keycode; BOOL shift, alt; // get the current keyboard if(KLGetCurrentKeyboardLayout(&keyboard)) return NO; // get the description of the current keyboard layout if(KLGetKeyboardLayoutProperty(keyboard, kKLKCHRData, &keyboardData)) return NO; // get pointer early numbers of blocks for each combination of modifiers modblocs = ((char *)keyboardData) + 2; // get number of blocks keycode->ascii nbblocs = *((UInt16 *)(keyboardData + 258)); // get pointer early blocks keycode-> ascii blocs = ((char *)keyboardData) + 260; // determining the size of all tables keycode-> ascii a scanner ifin = nbblocs*128; // determining pointer early in the tables of dead keys deadkeys = blocs+ifin; // Now it runs blocks keycode-> ascii to find the car ascii for (ix=0; ix<ifin ; ix++) { if (blocs[ix]==pcar) { // found ascii value: now we must determine which block it is keycode = ix & 0×7f; // 0111 1111 mask numbloc = ix >> 7; break; } } // not found: bail out (error) if (ix >= ifin) return NO; // from block number, we must find the combination of modifiers using this block for (ix=0; ix<15; ix++) { // it does not address whether the modifiers are not "capital" and "option" if (ix&1 || ix&4) continue; // Combining modifiers found for the block if (modblocs[ix]==numbloc) { shift = (ix&2) ? YES : NO; alt = (ix&8) ? YES : NO; break; } } // combination modifiers not found: bail if (ix>=15) return NO; // save our parameters *pkeycode=keycode; *pshift=shift; *palt=alt; return YES;}
- 将字符转换为键盘码的代码
- 采用native2ascii工具将中文字符的资源文件转换为Unicode代码格式的文件
- C#中将字符转换为键盘的键值keycode
- 从键盘接受一个字符串(String),并将其转换为字符型(char)
- 将传入的任意中文字符转换为拼音
- 将16进制的数据转换为字符
- 将整数转换为相应的一个字符数组
- TrueTypeFont(2)--如何将转换为在 Windows 95 中的 TrueType 标志符号索引的 Unicode 字符代码
- 将16进制Ascii码转换为string类型的电脑按键字符
- 将字符型转换为整型
- 如何将字符数组转换为字符串
- 将一个数转换为字符输出
- 将字符(串)转换为十六进制数
- 将TataTable转换为json字符
- 将字符数字转换为整型数字
- 将数字1234转换为字符1234
- Python将图片转换为字符画
- 将两个字符转换为一个字节
- 睡前故事
- C# 使用sqlite 轻量级数据库
- qq项目第一天(java JFrame 标题栏 最小化 最大化 拖动窗体)
- POJ 3914 Dull windows中动态链接库DLL在内存中的加载 算法模拟
- 解决iPhone网络软件在睡眠情况断线问题
- 将字符转换为键盘码的代码
- 实战技巧:goto语句的替代实现方式
- Linux 磁盘分区和文件系统
- UML--类图
- 用Git+Sphinx记笔记?
- oracle 11g RAC 的一些基本概念(四)
- http://blog.csdn.net/masterz/article/details/6232585
- The SMAQ stack for big data
- Steve Jobs Said