首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

如何让Command-W在Java或Clojure中关闭Mac OS上的窗口

要让Command-W在Java或Clojure中关闭Mac OS上的窗口,您需要使用Java Native Interface (JNI) 或Java Native Access (JNA) 来访问底层操作系统API。以下是一个使用Java Swing和JNA实现的示例:

  1. 首先,您需要下载JNA库。您可以从这里下载JNA库,并将其添加到Java项目的类路径中。
  2. 接下来,创建一个Java类,并添加以下代码:
代码语言:java
复制

import com.sun.jna.Library;

import com.sun.jna.Native;

import javax.swing.*;

import java.awt.event.ActionEvent;

import java.awt.event.KeyEvent;

public class CloseWindowDemo {

代码语言:txt
复制
public interface Carbon extends Library {
代码语言:txt
复制
    Carbon INSTANCE = Native.load("Carbon", Carbon.class);
代码语言:txt
复制
    int kVK_ANSI_W = 0x0D;
代码语言:txt
复制
    int kVK_Command = 0x37;
代码语言:txt
复制
    int GetCurrentKeyModifiers();
代码语言:txt
复制
    boolean GetWindowInfo(int windowRef, int infoType, int[] info);
代码语言:txt
复制
    int GetControlOwner(int controlRef);
代码语言:txt
复制
    int GetControlOwner(int controlRef, int[] ownerRef);
代码语言:txt
复制
    int GetControlOwner(int controlRef, int[] ownerRef, int[] ownerWindow);
代码语言:txt
复制
    int GetControlOwner(int controlRef, int[] ownerRef, int[] ownerWindow, int[] ownerPid);
代码语言:txt
复制
    int GetWindowOwner(int windowRef);
代码语言:txt
复制
    int GetWindowOwner(int windowRef, int[] ownerRef);
代码语言:txt
复制
    int GetWindowOwner(int windowRef, int[] ownerRef, int[] ownerWindow);
代码语言:txt
复制
    int GetWindowOwner(int windowRef, int[] ownerRef, int[] ownerWindow, int[] ownerPid);
代码语言:txt
复制
    int GetWindowModality(int windowRef, int[] modality);
代码语言:txt
复制
    int SetWindowModality(int windowRef, int modality, int[] displayDevice);
代码语言:txt
复制
    int GetWindowTitle(int windowRef, byte[] title, int maxLength);
代码语言:txt
复制
    int GetWindowBounds(int windowRef, int boundsRegion, int[] bounds);
代码语言:txt
复制
    int GetWindowRegion(int windowRef, int regionCode, int[] region);
代码语言:txt
复制
    int GetWindowProperty(int windowRef, int selector, int[] attributes);
代码语言:txt
复制
    int ChangeWindowAttributes(int windowRef, int[] attributes, int[] attributes);
代码语言:txt
复制
    int MoveWindow(int windowRef, int x, int y, int[] region);
代码语言:txt
复制
    int ResizeWindow(int windowRef, int w, int h, int[] region);
代码语言:txt
复制
    int DragWindow(int windowRef, int partCode, int[] region);
代码语言:txt
复制
    int TrackGoAway(int windowRef, int flags);
代码语言:txt
复制
    int GetWindowKind(int windowRef, int[] kind);
代码语言:txt
复制
    int GetWindowStandardState(int windowRef, int[] standardState);
代码语言:txt
复制
    int GetWindowZOrder(int windowRef, int[] windowZOrder);
代码语言:txt
复制
    int GetWindowAttributes(int windowRef, int[] attributes);
代码语言:txt
复制
    int GetWindowGroup(int windowRef, int[] windowGroup);
代码语言:txt
复制
    int GetWindowProperty(int windowRef, int selector, int[] attributes);
代码语言:txt
复制
    int SetWindowProperty(int windowRef, int selector, int attributes);
代码语言:txt
复制
    int DisposeWindow(int windowRef);
代码语言:txt
复制
    int GetWindowPID(int windowRef);
代码语言:txt
复制
    int GetWindowOwnerProcessID(int windowRef);
代码语言:txt
复制
    int GetWindowModality(int windowRef, int[] modality, int[] attributes);
代码语言:txt
复制
    int SetWindowModality(int windowRef, int modality, int[] attributes);
代码语言:txt
复制
    int GetWindowTitle(int windowRef, byte[] title, int maxLength, int[] attributes);
代码语言:txt
复制
    int GetWindowBounds(int windowRef, int boundsRegion, int[] bounds, int[] attributes);
代码语言:txt
复制
    int GetWindowRegion(int windowRef, int regionCode, int[] region, int[] attributes);
代码语言:txt
复制
    int GetWindowProperty(int windowRef, int selector, int[] attributes, int[] attributes);
代码语言:txt
复制
    int ChangeWindowAttributes(int windowRef, int[] attributes, int[] attributes);
代码语言:txt
复制
    int MoveWindow(int windowRef, int x, int y, int[] region, int[] attributes);
代码语言:txt
复制
    int ResizeWindow(int windowRef, int w, int h, int[] region, int[] attributes);
代码语言:txt
复制
    int DragWindow(int windowRef, int partCode, int[] region, int[] attributes);
代码语言:txt
复制
    int TrackGoAway(int windowRef, int flags, int[] attributes);
代码语言:txt
复制
    int GetWindowKind(int windowRef, int[] kind, int[] attributes);
代码语言:txt
复制
    int GetWindowStandardState(int windowRef, int[] standardState, int[] attributes);
代码语言:txt
复制
    int GetWindowZOrder(int windowRef, int[] windowZOrder, int[] attributes);
代码语言:txt
复制
    int GetWindowAttributes(int windowRef, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowGroup(int windowRef, int[] windowGroup, int[] attributes);
代码语言:txt
复制
    int GetWindowProperty(int windowRef, int selector, int[] attributes, int[] attributes);
代码语言:txt
复制
    int SetWindowProperty(int windowRef, int selector, int attributes, int[] attributes);
代码语言:txt
复制
    int DisposeWindow(int windowRef, int[] attributes);
代码语言:txt
复制
    int GetWindowPID(int windowRef, int[] attributes);
代码语言:txt
复制
    int GetWindowOwnerProcessID(int windowRef, int[] attributes);
代码语言:txt
复制
    int GetWindowModality(int windowRef, int[] modality, int[] attributes, int[] attributes);
代码语言:txt
复制
    int SetWindowModality(int windowRef, int modality, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowTitle(int windowRef, byte[] title, int maxLength, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowBounds(int windowRef, int boundsRegion, int[] bounds, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowRegion(int windowRef, int regionCode, int[] region, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowProperty(int windowRef, int selector, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int ChangeWindowAttributes(int windowRef, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int MoveWindow(int windowRef, int x, int y, int[] region, int[] attributes, int[] attributes);
代码语言:txt
复制
    int ResizeWindow(int windowRef, int w, int h, int[] region, int[] attributes, int[] attributes);
代码语言:txt
复制
    int DragWindow(int windowRef, int partCode, int[] region, int[] attributes, int[] attributes);
代码语言:txt
复制
    int TrackGoAway(int windowRef, int flags, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowKind(int windowRef, int[] kind, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowStandardState(int windowRef, int[] standardState, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowZOrder(int windowRef, int[] windowZOrder, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowAttributes(int windowRef, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowGroup(int windowRef, int[] windowGroup, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowProperty(int windowRef, int selector, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int SetWindowProperty(int windowRef, int selector, int attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int DisposeWindow(int windowRef, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowPID(int windowRef, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowOwnerProcessID(int windowRef, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowModality(int windowRef, int[] modality, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int SetWindowModality(int windowRef, int modality, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowTitle(int windowRef, byte[] title, int maxLength, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowBounds(int windowRef, int boundsRegion, int[] bounds, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowRegion(int windowRef, int regionCode, int[] region, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowProperty(int windowRef, int selector, int[] attributes, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int ChangeWindowAttributes(int windowRef, int[] attributes, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int MoveWindow(int windowRef, int x, int y, int[] region, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int ResizeWindow(int windowRef, int w, int h, int[] region, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int DragWindow(int windowRef, int partCode, int[] region, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int TrackGoAway(int windowRef, int flags, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowKind(int windowRef, int[] kind, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowStandardState(int windowRef, int[] standardState, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowZOrder(int windowRef, int[] windowZOrder, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowAttributes(int windowRef, int[] attributes, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowGroup(int windowRef, int[] windowGroup, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowProperty(int windowRef, int selector, int[] attributes, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int SetWindowProperty(int windowRef, int selector, int attributes, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int DisposeWindow(int windowRef, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowPID(int windowRef, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowOwnerProcessID(int windowRef, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowModality(int windowRef, int[] modality, int[] attributes, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int SetWindowModality(int windowRef, int modality, int[] attributes, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowTitle(int windowRef, byte[] title, int maxLength, int[] attributes, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowBounds(int windowRef, int boundsRegion, int[] bounds, int[] attributes, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowRegion(int windowRef, int regionCode, int[] region, int[] attributes, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowProperty(int windowRef, int selector, int[] attributes, int[] attributes, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int ChangeWindowAttributes(int windowRef, int[] attributes, int[] attributes, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int MoveWindow(int windowRef, int x, int y, int[] region, int[] attributes, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int ResizeWindow(int windowRef, int w, int h, int[] region, int[] attributes, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int DragWindow(int windowRef, int partCode, int[] region, int[] attributes, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int TrackGoAway(int windowRef, int flags, int[] attributes, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowKind(int windowRef, int[] kind, int[] attributes, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowStandardState(int windowRef, int[] standardState, int[] attributes, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowZOrder(int windowRef, int[] windowZOrder, int[] attributes, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowAttributes(int windowRef, int[] attributes, int[] attributes, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowGroup(int windowRef, int[] windowGroup, int[] attributes, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowProperty(int windowRef, int selector, int[] attributes, int[] attributes, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int SetWindowProperty(int windowRef, int selector, int attributes, int[] attributes, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int DisposeWindow(int windowRef, int[] attributes, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowPID(int windowRef, int[] attributes, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowOwnerProcessID(int windowRef, int[] attributes, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowModality(int windowRef, int[] modality, int[] attributes, int[] attributes, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int SetWindowModality(int windowRef, int modality, int[] attributes, int[] attributes, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowTitle(int windowRef, byte[] title, int maxLength, int[] attributes, int[] attributes, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowBounds(int windowRef, int boundsRegion, int[] bounds, int[] attributes, int[] attributes, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowRegion(int windowRef, int regionCode, int[] region, int[] attributes, int[] attributes, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowProperty(int windowRef, int selector, int[] attributes, int[] attributes, int[] attributes, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int ChangeWindowAttributes(int windowRef, int[] attributes, int[] attributes, int[] attributes, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int MoveWindow(int windowRef, int x, int y, int[] region, int[] attributes, int[] attributes, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int ResizeWindow(int windowRef, int w, int h, int[] region, int[] attributes, int[] attributes, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int DragWindow(int windowRef, int partCode, int[] region, int[] attributes, int[] attributes, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int TrackGoAway(int windowRef, int flags, int[] attributes, int[] attributes, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowKind(int windowRef, int[] kind, int[] attributes, int[] attributes, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowStandardState(int windowRef, int[] standardState, int[] attributes, int[] attributes, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowZOrder(int windowRef, int[] windowZOrder, int[] attributes, int[] attributes, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowAttributes(int windowRef, int[] attributes, int[] attributes, int[] attributes, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowGroup(int windowRef, int[] windowGroup, int[] attributes, int[] attributes, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowProperty(int windowRef, int selector, int[] attributes, int[] attributes, int[] attributes, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int SetWindowProperty(int windowRef, int selector, int attributes, int[] attributes, int[] attributes, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int DisposeWindow(int windowRef, int[] attributes, int[] attributes, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowPID(int windowRef, int[] attributes, int[] attributes, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowOwnerProcessID(int windowRef, int[] attributes, int[] attributes, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowModality(int windowRef, int[] modality, int[] attributes, int[] attributes, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int SetWindowModality(int windowRef, int modality, int[] attributes, int[] attributes, int[] attributes, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowTitle(int windowRef, byte[] title, int maxLength, int[] attributes, int[] attributes, int[] attributes);
代码语言:txt
复制
    int GetWindowBounds(int windowRef, int boundsRegion, int[] bounds, int[] attributes, int[] attributes);
页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

  • 领券