简体   繁体   中英

How can I draw “hello world” on the screen in OS X?

I've written some scripts that allow the user to move the mouse around by voice by referring to screen coordinates in OS X. Now, to make these scripts easier to use, I want to write a script that allows the user to impose along the top and left edges of the screen transparent rulers – just tics and numbers indicating distance (in pixels) from the upper-left corner of the screen. I want these rulers to remain visible at all times, staying frontmost even when the user switches between applications.

I suspect that I may need to use Objective-C, but I otherwise have no idea how to start. If someone could just tell me how to print “hello world” to the screen in OS X Yosemite – just characters, with no fill – I would be tremendously grateful.

http://www.binpress.com/tutorial/objectivec-lesson-1-hello-world/41

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[])
{
        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
        NSLog (@"Hello, World!");
        [pool drain];
        return 0;
}

What you probably want to do here is create two windows, one for each "ruler". The windows need to be set to a very high "level" to float above the other windows, and they need to be set to not respond to mouse events, so you can click "through" them to windows below.

If you read the NSWindow class documentation , it'll give you the information you need. Pay particular attention to the setLevel , setIgnoresMouseEvents , and setOpaque methods.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM