objective c - Capturing NSEvent to add modifier Issue -


i'm trying programmatically hold down option key user in cocoa app.

for life of me can't seem grab nsevent modify , re-post it. still want capture mousedown event because use location - i've been trying grab event , add modifier flag doesn't seem work. on appreciated.

this i've done:

- (void)mousedown:(nsevent *)theevent {     [super mousedown:theevent];      if(!(theevent.modifierflags == nsalternatekeymask)){          nsevent *newevent = [nsevent keyeventwithtype:                                       theevent.type                                       location:theevent.locationinwindow                                        modifierflags:nsalternatekeymask                                        timestamp:theevent.timestamp                                        windownumber:theevent.windownumber                                        context:theevent.context                                        characters:@""                                       charactersignoringmodifiers:@""                                       isarepeat:yes                                       keycode:0];            [super mousedown:newevent];     }    } 

i've tried variations of cgpostevent- never seems work either. apparently posting modifier flag more difficult looks.

thanks

i solved code-

- (void)mousedown:(nsevent *)theevent {      if(!(theevent.modifierflags == nsalternatekeymask)){          [super mousedown:[self createnewevent:theevent]];     }     else {         [super mousedown:theevent];      } }  - (nsevent *)createnewevent:(nsevent *)theevent {        nsevent *newevent = [nsevent                          keyeventwithtype:nskeydown                          location:theevent.locationinwindow                          modifierflags:nsalternatekeymask                          timestamp:theevent.timestamp                          windownumber:theevent.windownumber                          context:theevent.context                          characters:@""                          charactersignoringmodifiers:@""                          isarepeat:no                          keycode:0];     return newevent; } 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -