Air Desktop应用程序中的两个显示器上的全屏仍显示菜单栏直到点击

时间:2015-04-05 10:37:26

标签: actionscript-3 air applescript

这让我发疯了...... 我为Macos创建了一个Air Nativeapplication。 计算机正在运行MacOs 10.10。

我在Displaying two fullscreen windows on two monitors in Adobe AIR on Mac OS X (Mavericks)尝试了这个 无济于事。到目前为止似乎没有任何改变。

但是,还有其他办法吗? 我试过苹果脚本:

tell application "System Events"
tell process "myapp"
    delay (5)
    click at {100, 100}
end tell

但是Mousehandler甚至没有在空中开火......尽管苹果公司说:

window" myapp"申请程序" adl"应用程序"系统事件"

我能尝试的其他任何事情? 谢谢!

1 个答案:

答案 0 :(得分:0)

经过长时间的聚会令人沮丧的搜索后,当我在Stackoverflow上找到一个控制鼠标的python脚本时,我想出了答案:

Python脚本是:

from Quartz.CoreGraphics import CGEventCreateMouseEvent
from Quartz.CoreGraphics import CGEventPost
from Quartz.CoreGraphics import kCGEventMouseMoved
from Quartz.CoreGraphics import kCGEventLeftMouseDown
from Quartz.CoreGraphics import kCGEventLeftMouseDown
from Quartz.CoreGraphics import kCGEventLeftMouseUp
from Quartz.CoreGraphics import kCGMouseButtonLeft
from Quartz.CoreGraphics import kCGHIDEventTap

def mouseEvent(type, posx, posy):
    theEvent = CGEventCreateMouseEvent(
                None, 
                type, 
                (posx,posy), 
                kCGMouseButtonLeft)
    CGEventPost(kCGHIDEventTap, theEvent)

def mousemove(posx,posy):
    mouseEvent(kCGEventMouseMoved, posx,posy);

def mouseclick(posx,posy):
    # uncomment this line if you want to force the mouse 
    # to MOVE to the click location first (I found it was not necessary).
    #mouseEvent(kCGEventMouseMoved, posx,posy);
    mouseEvent(kCGEventLeftMouseDown, posx,posy);
    mouseEvent(kCGEventLeftMouseUp, posx,posy);
mouseclick(200,200)

然后我通过NativeProcess调用此脚本。 Class在应用程序存储目录中生成python文件并运行它。 我在onFullscreenEvent处理程序上运行它。 使用MacOS 10.10.3

就像魅力一样

喝彩!

package  {

    import flash.events.IOErrorEvent;
    import flash.filesystem.FileStream;
    import flash.filesystem.FileMode;
    import flash.events.Event;
    import flash.desktop.NativeProcess
    import flash.events.NativeProcessExitEvent
    import flash.desktop.NativeProcessStartupInfo
    import flash.events.ProgressEvent;
    import flash.filesystem.File;
    public class MouseClick extends Object {
        private static var process:NativeProcess
        private static var _pythonfilepath:String
        private static var _pythonfilename:String="MouseClick.py"
        private static var _pythonfile:File
        private static var _pythonstring:String="from Quartz.CoreGraphics import CGEventCreateMouseEvent\nfrom Quartz.CoreGraphics import CGEventPost\nfrom Quartz.CoreGraphics import kCGEventMouseMoved\nfrom Quartz.CoreGraphics import kCGEventLeftMouseDown\nfrom Quartz.CoreGraphics import kCGEventLeftMouseDown\nfrom Quartz.CoreGraphics import kCGEventLeftMouseUp\nfrom Quartz.CoreGraphics import kCGMouseButtonLeft\nfrom Quartz.CoreGraphics import kCGHIDEventTap\n\ndef mouseEvent(type, posx, posy):\n        theEvent = CGEventCreateMouseEvent(\n                    None, \n                    type, \n                    (posx,posy), \n                    kCGMouseButtonLeft)\n        CGEventPost(kCGHIDEventTap, theEvent)\n\ndef mousemove(posx,posy):\n        mouseEvent(kCGEventMouseMoved, posx,posy);\n\ndef mouseclick(posx,posy):\n        # uncomment this line if you want to force the mouse \n        # to MOVE to the click location first (I found it was not necessary).\n        #mouseEvent(kCGEventMouseMoved, posx,posy);\n        mouseEvent(kCGEventLeftMouseDown, posx,posy);\n        mouseEvent(kCGEventLeftMouseUp, posx,posy);\nmouseclick(200,200)";
        public function MouseClick(){
            super();    

        };

        public static function click(): void {
            _pythonfile=File.applicationStorageDirectory.resolvePath(_pythonfilename)
            _pythonfilepath=_pythonfile.nativePath;
            //
            if(!_pythonfile.exists){ 
                    _pythonfile = new File(_pythonfilepath);
                    var fileStream:FileStream = new FileStream();
                    fileStream.open(_pythonfile, FileMode.WRITE);
                    fileStream.writeUTFBytes(_pythonstring);
                    fileStream.close();
            }

            var nativeProcessStartupInfo: NativeProcessStartupInfo = new NativeProcessStartupInfo();
            var file:File = File.applicationDirectory.resolvePath("/usr/bin/python");
            nativeProcessStartupInfo.executable = file;

            var link =File.applicationDirectory.resolvePath("MouseClick.py").nativePath

            var processArgs: Vector.<String> = new Vector.<String> ();

            processArgs[0] = _pythonfilepath;
            nativeProcessStartupInfo.arguments = processArgs;
            process = new NativeProcess();
            process.start(nativeProcessStartupInfo);
            addNativeProcessListeners();
        }
        private static function removeNativeProcessListeners():void{
                process.removeEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData);
                process.removeEventListener(ProgressEvent.STANDARD_ERROR_DATA, onErrorData);
                process.removeEventListener(NativeProcessExitEvent.EXIT, onExit);
                process.removeEventListener(IOErrorEvent.STANDARD_OUTPUT_IO_ERROR, onIOError);
                process.removeEventListener(IOErrorEvent.STANDARD_ERROR_IO_ERROR, onIOError);
        };
        private static function addNativeProcessListeners():void{
                process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData);
                process.addEventListener(ProgressEvent.STANDARD_ERROR_DATA, onErrorData);
                process.addEventListener(NativeProcessExitEvent.EXIT, onExit);
                process.addEventListener(IOErrorEvent.STANDARD_OUTPUT_IO_ERROR, onIOError);
                process.addEventListener(IOErrorEvent.STANDARD_ERROR_IO_ERROR, onIOError);
        };
        public static function onOutputData(event: ProgressEvent): void {
            removeNativeProcessListeners()
        }

        public static function onErrorData(event: ProgressEvent): void {
            trace("could not send video successfully error: "+process.standardError.readUTFBytes(process.standardError.bytesAvailable),"err")
            removeNativeProcessListeners()
        }

        public static function onExit(event: NativeProcessExitEvent): void {

            removeNativeProcessListeners()

        }
        public static function onIOError(event: IOErrorEvent): void {
            trace("could not send video successfully error onIOError: "+event.toString(),"err");
        }

    }

}