Actually in latest Pharo keyboard events are extended to get the pressed
key:

key
^Smalltalk os keyForValue: keyValue

I tested it in windows, mac and unix some time ago and it used to work :)

On Tue, Jun 24, 2014 at 10:18 AM, [email protected] <[email protected]>
wrote:

> On Tue, Jun 24, 2014 at 10:07 AM, Yuriy Tymchuk <[email protected]>
> wrote:
>
>> Hi everyone,
>>
>> sorry, if I’m annoying with this question, but is there a way to handle
>> keyboard events (on mac) in a normal way? Because keyUp and keyDown do not
>> have any information about the key itself. I know that it’s a long story
>> also related with vm but maybe someone made some hacks to solve this
>> problem?
>>
>> Cheers
>> Uko
>>
>
> The logic is in sqSqueakOSXApplication+events.m
>
> Now, I do not have the latest version but it is true that keyUp and
> keyDown are not handled very nicely there.
>
> KeyDown doesn't seem to have any code (but one could set something there
> as the code is available). KeyUp has something.
>
> I do not know why things are done this way. There may be side effects in
> the VM if one changes the way things are...
>
> Good luck.
>
>  (void) recordCharEvent:(NSString *) unicodeString fromView:
> (NSView<sqSqueakOSXView> *) mainView {
> sqKeyboardEvent evt;
>  unichar unicode;
> unsigned char macRomanCharacter;
> NSInteger i;
>  NSRange picker;
> NSUInteger totaLength;
>  evt.type = EventTypeKeyboard;
>  evt.timeStamp = (int) ioMSecs();
> picker.location = 0;
> picker.length = 1;
>  totaLength = [unicodeString length];
> for (i=0;i < totaLength;i++) {
>   unicode = [unicodeString characterAtIndex: i];
>  if ([mainView lastSeenKeyBoardStrokeDetails]) {
> evt.modifiers = [self translateCocoaModifiersToSqueakModifiers: [[mainView
> lastSeenKeyBoardStrokeDetails] modifierFlags]];
>  evt.charCode = [[mainView lastSeenKeyBoardStrokeDetails] keyCode];
> } else {
> evt.modifiers = 0;
>  evt.charCode = 0;
> }
>  if ((evt.modifiers & CommandKeyBit) && (evt.modifiers & ShiftKeyBit)) {
>  /* command and shift */
>             if ((unicode >= 97) && (unicode <= 122)) {
> /* convert ascii code of command-shift-letter to upper case */
> unicode = unicode - 32;
>             }
> }
>  NSString *lookupString = [[NSString alloc] initWithCharacters: &unicode
> length: 1];
>  [lookupString getBytes: &macRomanCharacter maxLength: 1 usedLength: NULL
> encoding: NSMacOSRomanStringEncoding
>    options: 0 range: picker remainingRange: NULL];
>  [lookupString release];
>  evt.pressCode = EventKeyDown;
>  unsigned short keyCodeRemembered = evt.charCode;
> evt.utf32Code = 0;
> evt.reserved1 = 0;
>  evt.windowIndex = (int)[[mainView windowLogic] windowIndex];
> [self pushEventToQueue: (sqInputEvent *)&evt];
>  evt.charCode = macRomanCharacter;
> evt.pressCode = EventKeyChar;
>  evt.modifiers = evt.modifiers;
> evt.utf32Code = unicode;
>   [self pushEventToQueue: (sqInputEvent *) &evt];
>  if (i > 1 || ![mainView lastSeenKeyBoardStrokeDetails]) {
> evt.pressCode = EventKeyUp;
> evt.charCode = keyCodeRemembered;
>  evt.utf32Code = 0;
> [self pushEventToQueue: (sqInputEvent *) &evt];
> }
>  }
>
> interpreterProxy->signalSemaphoreWithIndex(gDelegateApp.squeakApplication.inputSemaphoreIndex);
>
> }
>
> --Phil
>
>

Reply via email to