some windows code
This commit is contained in:
parent
d9ff38e221
commit
ed672439a4
|
@ -1,5 +1,5 @@
|
||||||
<component name="ArtifactManager">
|
<component name="ArtifactManager">
|
||||||
<artifact type="jar" name="skunkworks:jar">
|
<artifact type="jar" build-on-make="true" name="skunkworks:jar">
|
||||||
<output-path>$PROJECT_DIR$/out/artifacts/skunkworks_jar</output-path>
|
<output-path>$PROJECT_DIR$/out/artifacts/skunkworks_jar</output-path>
|
||||||
<root id="archive" name="skunkworks.jar">
|
<root id="archive" name="skunkworks.jar">
|
||||||
<element id="module-output" name="skunkworks" />
|
<element id="module-output" name="skunkworks" />
|
||||||
|
|
|
@ -48,12 +48,18 @@ public interface User32Extra extends User32 {
|
||||||
|
|
||||||
int WH_SHELL = 10;
|
int WH_SHELL = 10;
|
||||||
|
|
||||||
|
int WM_TIMER = 0x0113;
|
||||||
|
|
||||||
int HSHELL_WINDOWCREATED = 1;
|
int HSHELL_WINDOWCREATED = 1;
|
||||||
// https://docs.microsoft.com/en-us/windows/desktop/inputdev/virtual-key-codes
|
// https://docs.microsoft.com/en-us/windows/desktop/inputdev/virtual-key-codes
|
||||||
int VK_LBUTTON = 0x01;
|
int VK_LBUTTON = 0x01;
|
||||||
int VK_RBUTTON = 0x02;
|
int VK_RBUTTON = 0x02;
|
||||||
int VK_MBUTTON = 0x04;
|
int VK_MBUTTON = 0x04;
|
||||||
|
|
||||||
|
int PM_NOREMOVE = 0x00;
|
||||||
|
int PM_REMOVE = 0x01;
|
||||||
|
int PM_NOYIELD = 0x02;
|
||||||
|
|
||||||
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-gettitlebarinfo
|
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-gettitlebarinfo
|
||||||
boolean GetTitleBarInfo(WinDef.HWND hwnd, TITLEBARINFO titlebarinfo);
|
boolean GetTitleBarInfo(WinDef.HWND hwnd, TITLEBARINFO titlebarinfo);
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
package com.danitheskunk.skunkworks.windows;
|
||||||
|
|
||||||
|
import com.sun.jna.Native;
|
||||||
|
import com.sun.jna.platform.win32.WinUser;
|
||||||
|
import com.sun.jna.win32.W32APIOptions;
|
||||||
|
|
||||||
|
public interface WinUserExtra extends WinUser, com.sun.jna.win32.StdCallLibrary {
|
||||||
|
WinUserExtra INSTANCE = Native.load("user32", WinUserExtra.class, W32APIOptions.DEFAULT_OPTIONS);
|
||||||
|
|
||||||
|
//todo: lpTimerFunc should be TIMERPROC
|
||||||
|
UINT_PTR SetTimer(HWND hWnd, UINT_PTR nIDEvent, UINT uElapse, PVOID lpTimerFunc);
|
||||||
|
}
|
|
@ -3,12 +3,10 @@ package com.danitheskunk.skunkworks.windows;
|
||||||
|
|
||||||
import com.danitheskunk.skunkworks.Recti;
|
import com.danitheskunk.skunkworks.Recti;
|
||||||
import com.danitheskunk.skunkworks.Util;
|
import com.danitheskunk.skunkworks.Util;
|
||||||
import com.danitheskunk.skunkworks.Vec2i;
|
|
||||||
import com.sun.jna.Native;
|
import com.sun.jna.Native;
|
||||||
import com.sun.jna.Pointer;
|
import com.sun.jna.Pointer;
|
||||||
import com.sun.jna.platform.win32.*;
|
import com.sun.jna.platform.win32.*;
|
||||||
import com.sun.jna.ptr.IntByReference;
|
import com.sun.jna.ptr.IntByReference;
|
||||||
import com.sun.jna.ptr.PointerByReference;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -139,6 +137,10 @@ public class Window {
|
||||||
return Util.nullTerminatedCharArrayToString(chars);
|
return Util.nullTerminatedCharArrayToString(chars);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getKey() {
|
||||||
|
return getExecutableName() + " $ " + getClassName();
|
||||||
|
}
|
||||||
|
|
||||||
private int getStyle() {
|
private int getStyle() {
|
||||||
var user32 = User32Extra.INSTANCE;
|
var user32 = User32Extra.INSTANCE;
|
||||||
return user32.GetWindowLong(hwnd, WinUser.GWL_STYLE);
|
return user32.GetWindowLong(hwnd, WinUser.GWL_STYLE);
|
||||||
|
@ -208,16 +210,13 @@ public class Window {
|
||||||
var walk = user32.GetAncestor(hwnd, WinUser.GA_ROOTOWNER);
|
var walk = user32.GetAncestor(hwnd, WinUser.GA_ROOTOWNER);
|
||||||
WinDef.HWND test;
|
WinDef.HWND test;
|
||||||
|
|
||||||
while(!(test = user32.GetLastActivePopup(walk)).equals(test)) {
|
|
||||||
if(user32.IsWindowVisible(test)) break;
|
|
||||||
walk = test;
|
|
||||||
}
|
|
||||||
var window = new Window(hwnd);
|
var window = new Window(hwnd);
|
||||||
|
if(walk == null) return false;
|
||||||
return walk.equals(hwnd) && user32.IsWindowVisible(hwnd) && window.getTitle().length() > 0 && !window.isToolWindow() && !window.isDwmCloaked() && !window.getClassName().equals("Progman");
|
return walk.equals(hwnd) && user32.IsWindowVisible(hwnd) && window.getTitle().length() > 0 && !window.isToolWindow() && !window.isDwmCloaked() && !window.getClassName().equals("Progman");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isToolWindow() {
|
public boolean isToolWindow() {
|
||||||
return (getStyle() & User32Extra.WS_EX_TOOLWINDOW) != 0;
|
return (getStyleEx() & User32Extra.WS_EX_TOOLWINDOW) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void move(Recti rectangle) {
|
public void move(Recti rectangle) {
|
||||||
|
@ -257,6 +256,14 @@ public class Window {
|
||||||
user32.SetWindowPos(hwnd, null, 0, 0, 0, 0, WinUser.SWP_FRAMECHANGED | WinUser.SWP_NOZORDER | WinUser.SWP_NOOWNERZORDER | WinUser.SWP_NOMOVE | WinUser.SWP_NOSIZE | WinUser.SWP_NOACTIVATE);
|
user32.SetWindowPos(hwnd, null, 0, 0, 0, 0, WinUser.SWP_FRAMECHANGED | WinUser.SWP_NOZORDER | WinUser.SWP_NOOWNERZORDER | WinUser.SWP_NOMOVE | WinUser.SWP_NOSIZE | WinUser.SWP_NOACTIVATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if(!(o instanceof Window)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return ((Window)o).hwnd.equals(this.hwnd);
|
||||||
|
}
|
||||||
|
|
||||||
//static functions
|
//static functions
|
||||||
public static List<Window> getAllVisible() {
|
public static List<Window> getAllVisible() {
|
||||||
var user32 = User32Extra.INSTANCE;
|
var user32 = User32Extra.INSTANCE;
|
||||||
|
@ -281,16 +288,47 @@ public class Window {
|
||||||
System.out.println("msg pump");
|
System.out.println("msg pump");
|
||||||
user32.TranslateMessage(msg);
|
user32.TranslateMessage(msg);
|
||||||
user32.DispatchMessage(msg);
|
user32.DispatchMessage(msg);
|
||||||
|
if(msg.message == User32Extra.WM_TIMER)
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void messageTick() {
|
||||||
|
//todo: check if this even works (switch to getmessage, and add timer function?)
|
||||||
|
var user32 = User32Extra.INSTANCE;
|
||||||
|
var msg = new WinUser.MSG();
|
||||||
|
//while(user32.PeekMessage(msg, null, 0, 0, User32Extra.PM_NOREMOVE)) {
|
||||||
|
user32.GetMessage(msg, null, 0, 0);
|
||||||
|
System.out.println("msg pump");
|
||||||
|
user32.TranslateMessage(msg);
|
||||||
|
user32.DispatchMessage(msg);
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
|
||||||
public static void onKey() {
|
public static void onKey() {
|
||||||
var user32 = User32Extra.INSTANCE;
|
var user32 = User32Extra.INSTANCE;
|
||||||
var kernel32 = Kernel32.INSTANCE;
|
var kernel32 = Kernel32.INSTANCE;
|
||||||
var res = user32.SetWindowsHookEx(User32Extra.WH_KEYBOARD_LL, new WinUser.HOOKPROC() {
|
var res = user32.SetWindowsHookEx(User32Extra.WH_KEYBOARD_LL, new WinUser.HOOKPROC() {
|
||||||
public WinDef.LRESULT callback(int nCode, WinDef.WPARAM wparam, WinDef.LPARAM lparam) {
|
public WinDef.LRESULT callback(int nCode, WinDef.WPARAM wparam, WinDef.LPARAM lparam) {
|
||||||
|
var kb = new WinUser.KBDLLHOOKSTRUCT() .newInstance(WinUser.KBDLLHOOKSTRUCT.class, lparam.toPointer());
|
||||||
|
System.out.println(kb.vkCode);
|
||||||
|
switch(wparam.intValue()) {
|
||||||
|
case User32Extra.WM_KEYDOWN:
|
||||||
|
|
||||||
|
System.out.println("WM_KEYDOWN");
|
||||||
|
break;
|
||||||
|
case User32Extra.WM_KEYUP:
|
||||||
|
System.out.println("WM_KEYUP");
|
||||||
|
break;
|
||||||
|
case User32Extra.WM_SYSKEYDOWN:
|
||||||
|
System.out.println("WM_SYSKEYDOWN");
|
||||||
|
break;
|
||||||
|
case User32Extra.WM_SYSKEYUP:
|
||||||
|
System.out.println("WM_SYSKEYUP");
|
||||||
|
break;
|
||||||
|
}
|
||||||
System.out.println("got some message a");
|
System.out.println("got some message a");
|
||||||
return new WinDef.LRESULT(0);
|
return user32.CallNextHookEx(null, nCode, wparam, lparam);
|
||||||
}
|
}
|
||||||
}, null, 0);
|
}, null, 0);
|
||||||
if(res == null) {
|
if(res == null) {
|
||||||
|
@ -316,4 +354,8 @@ public class Window {
|
||||||
throw new RuntimeException("Couldn't setwindowhookex: " + Native.getLastError());
|
throw new RuntimeException("Couldn't setwindowhookex: " + Native.getLastError());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void onTimer(int ms) {
|
||||||
|
WinUserExtra.INSTANCE.SetTimer(null, null, new WinDef.UINT(ms), null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue