JNA-如何调用系统功能? (旋转,关闭屏幕) [英] JNA - How to call System-functions? (rotate, screen off)
问题描述
我完全不熟悉JNA接口(?库?)-但我看到某些系统功能只能通过JNA在Java中访问.我想做一些显示工作,即旋转和关闭显示器.对于这两个功能,我都必须调用一些系统功能-对于关闭显示器,我发现了链接.但老实说,我不知道如何从其中之一入手.
I am completely new to the JNA interface (? library?) - but I see some of the System-functions are only accessible in Java via JNA. I wanna do some display-stuff, namely rotating and turn-off-monitor. For both function I have to call some system-functions - for the turn-off-monitor I found the link as well as for the rotate the link. But to be honest, I have no real clue how to start with one of them.
有人可以提出一个想法来开始.如何实施?
Could somebody give an idea how to start resp. how to implement?
推荐答案
好的,我必须尝试打开和关闭显示器,然后才能正常工作!太酷了!
OK, I had to try the monitor on and off bit, and it worked! Too cool!
import com.sun.jna.Native;
import com.sun.jna.platform.win32.WinDef.HWND;
import com.sun.jna.platform.win32.WinDef.LPARAM;
import com.sun.jna.platform.win32.WinDef.LRESULT;
import com.sun.jna.platform.win32.WinDef.WPARAM;
import com.sun.jna.platform.win32.WinUser;
import com.sun.jna.win32.StdCallLibrary;
public class TurnOffMonitor {
public interface User32 extends StdCallLibrary {
User32 INSTANCE = (User32) Native.loadLibrary("user32", User32.class);
int SC_MONITORPOWER = 0xF170;
int SC_MONITOR_OFF = 2;
int SC_MONITOR_ON = -1;
LRESULT SendMessageA(HWND paramHWND, int paramInt, WPARAM paramWPARAM,
LPARAM paramLPARAM);
LRESULT SendMessageA(HWND paramHWND, int paramInt, int paramInt2,
LPARAM paramLPARAM);
}
private static final long SLEEP_TIME = 4 * 1000; // 4 seconds
public static void main(String[] args) {
final User32 user32 = User32.INSTANCE;
System.out.println("Foo");
user32.SendMessageA(WinUser.HWND_BROADCAST, WinUser.WM_SYSCOMMAND,
User32.SC_MONITORPOWER, new LPARAM(User32.SC_MONITOR_OFF));
try {
Thread.sleep(SLEEP_TIME);
} catch (InterruptedException e) {}
user32.SendMessageA(WinUser.HWND_BROADCAST, WinUser.WM_SYSCOMMAND,
User32.SC_MONITORPOWER, new LPARAM(User32.SC_MONITOR_ON));
}
}
这篇关于JNA-如何调用系统功能? (旋转,关闭屏幕)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!