Skip to content
Snippets Groups Projects
Commit 89724102 authored by NikolaBabic's avatar NikolaBabic
Browse files

Added checkMessages method

parent 65c8d3d9
No related branches found
No related tags found
2 merge requests!45Prototype to Master for Milestone 5,!41Feature OS interface
......@@ -2,6 +2,7 @@ package model;
import com.sun.jna.platform.win32.User32;
import com.sun.jna.platform.win32.WinDef;
import com.sun.jna.platform.win32.WinUser;
import java.util.HashMap;
......@@ -12,9 +13,13 @@ public class OSInterface implements HotkeyDetector, HotkeyRegistration, InputEmu
private User32 user32 = User32.INSTANCE;
private WinDef.HWND hwnd;
private HashMap<Integer, Hotkey> registeredKeys;
private HashMap<Integer, Boolean> pressedKeys;
private WinUser.MSG msg;
private OSInterface() {
registeredKeys = new HashMap<>();
pressedKeys = new HashMap<>();
msg = new WinUser.MSG();
}
/**
......@@ -27,12 +32,27 @@ public class OSInterface implements HotkeyDetector, HotkeyRegistration, InputEmu
return instance;
}
/**
* Must be called in a loop to check the message queue of the window.
*/
public void checkMessages() {
boolean hotkeyMsg = user32.PeekMessage(msg, hwnd, 0, 0, 1);
if (hotkeyMsg) {
if (msg.message == User32.WM_HOTKEY) {
if (registeredKeys.containsKey(msg.wParam.intValue())) {
pressedKeys.put(msg.wParam.intValue(), true);
}
}
}
}
/**
* Sets the HWND to use for interfacing with the OS.
* @param hwnd The HWND of a window.
*/
public void setHWND(WinDef.HWND hwnd) {
this.hwnd = hwnd;
if (this.hwnd == null)
this.hwnd = hwnd;
}
@Override
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment