今天我从一个简单的项目开始,它应该将字符串转换为带有键码的数组以模拟击键。我的问题是我不能使用 char 作为字典的 id 来将该 char 转换为键码。
//Declare a Dictionary
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
//Add the Basic data for keycodes (i know that there are some missing)
[dictionary setObject:@"0x00" forKey:@"a"]; //a
[dictionary setObject:@"0x0B" forKey:@"b"]; // b
[dictionary setObject:@"0x08" forKey:@"c"]; //c
[dictionary setObject:@"0x02" forKey:@"d"]; // d
[dictionary setObject:@"0x0E" forKey:@"e"]; //e
[dictionary setObject:@"0x03" forKey:@"f"]; //f
[dictionary setObject:@"0x05" forKey:@"g"]; //g
[dictionary setObject:@"0x04" forKey:@"h"]; //h
[dictionary setObject:@"0x22" forKey:@"i"]; //i
[dictionary setObject:@"0x26" forKey:@"j"]; //j
[dictionary setObject:@"0x28" forKey:@"k"]; //k
[dictionary setObject:@"0x25" forKey:@"l"];//l
[dictionary setObject:@"0x2D" forKey:@"m"];//m
[dictionary setObject:@"0x2E" forKey:@"n"];//n
[dictionary setObject:@"0x1F" forKey:@"o"];//o
[dictionary setObject:@"0x23" forKey:@"p"];//p
[dictionary setObject:@"0x0C" forKey:@"q"];//q
[dictionary setObject:@"0x0F" forKey:@"r"];//r
[dictionary setObject:@"0x01" forKey:@"s"];//s
[dictionary setObject:@"0x11" forKey:@"t"];//t
[dictionary setObject:@"0x20" forKey:@"u"];//u
[dictionary setObject:@"0x09" forKey:@"v"];//v
[dictionary setObject:@"0x0D" forKey:@"w"];//w
[dictionary setObject:@"0x07" forKey:@"x"];//x
[dictionary setObject:@"0x10" forKey:@"y"];//y
[dictionary setObject:@"0x06" forKey:@"z"];//z
NSString *workwith = [_mess stringValue]; //Get String from Interface
long stringl = [workwith length]; //Get lenght of the String
int a = 0;
char text[stringl-1]; //make a array with the lenght of the string
while (a < stringl) { //fill this array with chars from the string
text[a] = [workwith characterAtIndex:a];
NSLog(@"%c",text[a]);
a++;
}
char fmat[stringl-1]; //make a second char to fill it with keycodes
int dnehmen = 0;
while (dnehmen <= stringl-1) {
fmat[dnehmen] = [dictionary objectForKey:@"%c",text[dnehmen]]; //stuck at this point
}
在最后一行,我尝试使用第一个数组中的 char 作为字典的 id 来获取第二个数组的键码。我收到一个错误,我不能使用 char 作为 id,所以我需要一个是从 char 获取键码。(我在这个网站上阅读了一些帖子,但我并没有真正理解他们做了什么)谢谢你的回答蒂姆