KeyCode <=> ASCII problem...
KeyCode <=> ASCII problem...
- Subject: KeyCode <=> ASCII problem...
- From: Thierry Bucco <email@hidden>
- Date: Tue, 13 May 2003 15:44:27 +0200
Hi,
Here is my problem...
I would like to send some text and command key to another application.
So I am using CGPostKeyboardEvent, it works fine...
In order to know the keycode to send to the desired application I use some
carbon functions (a sample I got on apple's website) to get keycode from
ascii char.
The functions are below :
-(OSStatus)InitAscii2KeyCodeTable
{
unsigned char *theCurrentKCHR, *ithKeyTable;
short count, i, j, resID;
Handle theKCHRRsrc;
ResType rType;
/* set up our table to all minus ones */
for (i=0;i<256; i++) keytable.transtable[i] = -1;
/* find the current kchr resource ID */
keytable.kchrID = (short) GetScriptVariable(smCurrentScript,
smScriptKeys);
/* get the current KCHR resource */
theKCHRRsrc = GetResource('KCHR', keytable.kchrID);
if (theKCHRRsrc == NULL) return resNotFound;
GetResInfo(theKCHRRsrc,&resID,&rType,keytable.KCHRname);
/* dereference the resource */
theCurrentKCHR = (unsigned char *) (*theKCHRRsrc);
/* get the count from the resource */
count = * (short *) (theCurrentKCHR + kTableCountOffset);
/* build inverse table by merging all key tables */
for (i=0; i<count; i++) {
ithKeyTable = theCurrentKCHR + kFirstTableOffset + (i * kTableSize);
for (j=0; j<kTableSize; j++) {
if ( keytable.transtable[ ithKeyTable[j] ] == -1)
keytable.transtable[ ithKeyTable[j] ] = j;
}
}
/* all done */
return noErr;
}
-(short)AsciiToKeyCode:(short)asciiCode
{
if (asciiCode >= 0 && asciiCode <= 255) return
keytable.transtable[asciiCode];
else return -1;
}
The problem I have is for the string
http://www.apple.com
I get
http://wwww;apple;com for french keyboard and http;//wwww.apple.com
for american keyboard.
Do you know what I missed ?
Thanks a lot for your help.
Thierry
sockho.com
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.