Type "ANY" String

Mac OSX specific forum
User avatar
Piero
Addict
Addict
Posts: 1172
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Type "ANY" String

Post by Piero »

Note: it may not work in some apps when replacing a multiline selection…

Code: Select all

ImportC ""
   CFRelease(CFTypeRef)
   CGEventKeyboardSetUnicodeString(keyEvent, len, uChar.s)
   CGEventCreateKeyboardEvent(CGEventSourceRef, CGVirtualKeyCode.U, KeyDown.L)
   CGEventPost(CGEventTapLocation, CGEventRef)
EndImport

Procedure Typestring(string.s)
   Protected keyEvent ; , *objPool = CocoaMessage(0, 0, "NSAutoreleasePool new")
   keyEvent = CGEventCreateKeyboardEvent(#nil, 0, #True)
   CGEventKeyboardSetUnicodeString(keyEvent, Len(string), string)
   CGEventPost(#kCGHIDEventTap, keyEvent)
   CFRelease(keyEvent) ; : CocoaMessage(0, *objPool, "release")
EndProcedure

CocoaMessage(0,CocoaMessage(0,0,"NSWorkspace sharedWorkspace"),"launchApplication:$",@"TextEdit")
Delay(1000) ; wait for textedit to activate
Typestring(~"🍍🍕😟\n")