ios - Objective-C how to convert a keystroke to ASCII character code? -


i need find way convert arbitrary character typed user ascii representation sent network service. current approach create lookup dictionary , send corresponding code. after creating dictionary, see hard maintain , determine if complete:

    __asciikeycodes[@"f1"] = @(112);     __asciikeycodes[@"f2"] = @(113);     __asciikeycodes[@"f3"] = @(114); //...     __asciikeycodes[@"a"] = @(97);     __asciikeycodes[@"b"] = @(98);     __asciikeycodes[@"c"] = @(99); 

is there better way ascii character code arbitrary key typed user (using standard 104 keyboard)?

objective c has base c primitive data types. there little trick can do. want set keystroke char, , cast int. default conversion in c char int char's ascii value. here's quick example.

char character= 'a'; nslog("a = %ld", (int)test);

console output = a = 97 go other way around, cast int char;

int asciivalue= (int)97; nslog("97 = %c", (char)asciivalue);

console output = 97 = a

alternatively, can direct conversion within initialization of int or char , store in variable.

char asciitocharof97 = (char)97; //stores 'a' in asciitocharof97

int chartoasciiofa = (int)'a'; //stores 97 in chartoasciiofa


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -