PB Cocoa Gurus Help Please
Posted: Thu Dec 04, 2025 4:10 pm
Help Please!
Is this "console app" easy to "port" to a PB Procedure(s.s)?
It's a text typing thing that works very well (via shell); it types any char
!
My PBCocoa is terrible!
Thanks!
Is this "console app" easy to "port" to a PB Procedure(s.s)?
It's a text typing thing that works very well (via shell); it types any char
My PBCocoa is terrible!
Thanks!
Code: Select all
#import <Foundation/Foundation.h>
#include <CoreGraphics/CGEvent.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
if (argc > 1) {
NSString *theString = [NSString stringWithUTF8String:argv[1]];
NSUInteger len = [theString length];
NSUInteger n, i = 0;
CGEventRef keyEvent = CGEventCreateKeyboardEvent(nil, 0, true);
unichar uChars[20];
while (i < len) {
n = i + 20;
if (n>len){n=len;}
[theString getCharacters:uChars range:NSMakeRange(i, n-i)];
CGEventKeyboardSetUnicodeString(keyEvent, n-i, uChars);
CGEventPost(kCGHIDEventTap, keyEvent); // key down
CGEventSetType(keyEvent, kCGEventKeyUp);
CGEventPost(kCGHIDEventTap, keyEvent); // key up (type 20 characters maximum)
CGEventSetType(keyEvent, kCGEventKeyDown);
i = n;
[NSThread sleepForTimeInterval:0.003]; // wait 3/1000 of second
}
CFRelease(keyEvent);
}
}
return 0;
}