@Override protected void doKeyPress(final int keyCode, final boolean shifted) throws InterruptedException { logger.log(Level.FINER, "doKeyPress " + keyCode + " " + shifted); while (isCtrlKeyDown()) { Thread.sleep(100); } final int lParam = 0x00000001 | 0x50 /* scancode */<< 16 | 0x01000000 /* extended */; final WPARAM wparam = new WinDef.WPARAM(keyCode); final WPARAM wparamShift = new WinDef.WPARAM(KeyEvent.VK_SHIFT); final LPARAM lparamDown = new WinDef.LPARAM(lParam); final LPARAM lparamUp = new WinDef.LPARAM(lParam | 1 << 30 | 1 << 31); if (shifted) { User32.INSTANCE.PostMessage(handler, WM_KEYDOWN, wparamShift, lparamDown); } User32.INSTANCE.PostMessage(handler, WM_KEYDOWN, wparam, lparamDown); User32.INSTANCE.PostMessage(handler, WM_KEYUP, wparam, lparamUp); if (shifted) { User32.INSTANCE.PostMessage(handler, WM_KEYUP, wparamShift, lparamUp); } }
@Override public void dispose() { super.dispose(); window.dispose(AppUI.getMainWindow()); if (ENABLED_NOTIFICATIONS) TrayHook.INSTANCE.UnregisterSystemTrayHook(); User32Ext.INSTANCE.SystemParametersInfo(SPI.SPI_SETWORKAREA, 0, old.getPointer(), 0); User32Ext.INSTANCE.DeregisterShellHookWindow(local); if (noExplorer) { backgroundWindow.getWindow().closeDisplay(); User32.INSTANCE.PostThreadMessage(keysThreadID, WM_QUIT, new WPARAM(), new LPARAM()); User32Ext.INSTANCE.SystemParametersInfo(SPI.SPI_SETMINIMIZEDMETRICS, oldMM.size(), oldMM.getPointer(), 0); } else { if (taskbar != null) User32.INSTANCE.ShowWindow(taskbar, SW_SHOW); } }
public boolean cmdSendCommandMsg(String[] args) { if (!checkArgumentLength(args, 3)) return false; WinPtr handle = findHandleWithXpath(args[0]); //xpath to HWND is first argument if (handle.isEmpty()) return false; int id = Integer.parseInt(args[1]); //context menu id is supplied as second argument int idLparam = Integer.parseInt(args[2]); //context menu id is supplied as second argument handle.convertToNativeHwnd(); //LRESULT result = //System.out.println("Send Message WM_COMMAND to " + handle.toString() + " PARAMS: " + id + ", " + idLparam); //api.user32.PostMessage(handle.hWnd, Api.WM_COMMAND, new WPARAM(id), new LPARAM(0)); api.user32.SendMessage(handle.hWnd, Api.WM_COMMAND, new WPARAM(id), new LPARAM(idLparam)); return true; }
public boolean cmdSendMessage(String[] args) { if (!checkArgumentLength(args, 4)) return false; WinPtr handle = findHandleWithXpath(args[0]); //xpath to HWND is first argument if (handle.isEmpty()) return false; int msg = Integer.parseInt(args[1]); int id = Integer.parseInt(args[2]); //context menu id is supplied as second argument int idLparam = Integer.parseInt(args[3]); //context menu id is supplied as second argument handle.convertToNativeHwnd(); //LRESULT result = //System.out.println("Send Message WM_COMMAND to " + handle.toString() + " PARAMS: " + id + ", " + idLparam); //api.user32.PostMessage(handle.hWnd, Api.WM_COMMAND, new WPARAM(id), new LPARAM(0)); api.user32.SendMessage(handle.hWnd, msg, new WPARAM(id), new LPARAM(idLparam)); return true; }
/** * Writes text to cmd.exe. * * @param text The text to write to cmd.exe. */ public final void write(final String text) { for (char c : text.toCharArray()) { /* Send the character to cmd.exe. */ User32.INSTANCE.PostMessage( this.hwnd, WinUser.WM_CHAR, new WPARAM(c), new LPARAM(0)); /* Normally cmd.exe won't need a WM_KEYUP, but if this is a * repeated series of characters (33, aaa, etc.) then * cmd.exe will ignore every character other than the first * one unless it gets a WM_KEYUP after each WM_CHAR. */ short vkey = User32.INSTANCE.VkKeyScan(c); int oemScan = User32.INSTANCE.MapVirtualKey( vkey & 0xff, 0); /* MAPVK_VK_TO_VSC */ User32.INSTANCE.PostMessage( this.hwnd, WinUser.WM_KEYUP, new WPARAM(vkey & 0xff), new LPARAM(0 | (oemScan << 16) | (3 << 31))); } }
public void iconAdded(NOTIFYICONDATA data) { if (true) return; System.out.println("Added: " + data.uID); if (!iconsMap.containsKey(data.guidItem)) iconsTask.add(() -> { NotificationButton btn = new NotificationButton(0, 0, 16, 16, "Test", data); btn.setOnButtonPress(() -> { User32Ext.INSTANCE.SendMessage(data.hWnd, WM_CONTEXTMENU, new WPARAM(Pointer.nativeValue(data.hWnd.getPointer())), new LPARAM()); }); icons.addComponent(btn); iconsMap.put(data.guidItem, btn); }); }
public boolean cmdSelectMenu(String[] args) { if (!checkArgumentLength(args, 1)) return false; WinPtr handle = findHandleWithXpath(args[0]); if (handle.isEmpty()) return false; int id = findMenuIdWithXpath(args[0]); handle.convertToNativeHwnd(); //LRESULT result = //System.out.println("PostMessage to " + handle.hWndStr + " for id " + id); api.user32.PostMessage(handle.hWnd, Api.WM_COMMAND, new WPARAM(id), new LPARAM(0)); //api.user32.SendMessage(handle.hWnd, Api.WM_COMMAND, new WPARAM(id), new LPARAM(0)); return true; }
public boolean cmdSelectContextMenuId(String[] args) { if (!checkArgumentLength(args, 2)) return false; WinPtr handle = findHandleWithXpath(args[0]); //xpath to HWND is first argument if (handle.isEmpty()) return false; int id = Integer.parseInt(args[1]); //context menu id is supplied as second argument handle.convertToNativeHwnd(); //LRESULT result = System.out.println("PostMessage to " + handle.toString() + " for id " + id + " - " + Api.MAKELONG(id, 0)); //api.user32.PostMessage(handle.hWnd, Api.WM_COMMAND, new WPARAM(id), new LPARAM(0)); api.user32.SendMessage(handle.hWnd, Api.WM_COMMAND, new WPARAM(Api.MAKELONG(id, 0)), new LPARAM(0)); return true; }
private static HWND getFirstChildHandle(final String title, final String text, final String control, final HWND itemHWND) { HWND firstChildHWND = null; HWND hWnd = Control.getHandle_(title, text, control); if (hWnd != null) { firstChildHWND = Win32.user32.SendMessage(hWnd, TVM_GETNEXTITEM, new WPARAM(TVGN_CHILD), itemHWND); } return firstChildHWND; }
private static HWND getFirstItemHandle(final String title, final String text, final String control) { HWND firstItemHWND = null; HWND hWnd = Control.getHandle_(title, text, control); if (hWnd != null) { firstItemHWND = Win32.user32.SendMessage(hWnd, TVM_GETNEXTITEM, new WPARAM(TVGN_ROOT), new LPARAM(0)); } return firstItemHWND; }
private static HWND getNextSiblingHandle(final String title, final String text, final String control, final HWND itemHWND) { HWND nextSiblingHWND = null; if (itemHWND != null) { HWND hWnd = Control.getHandle_(title, text, control); if (hWnd != null) { nextSiblingHWND = Win32.user32.SendMessage(hWnd, TVM_GETNEXTITEM, new WPARAM(TVGN_NEXT), itemHWND); } } return nextSiblingHWND; }
/** * Retrieves the item according to index in a ListBox or ComboBox. * * Certain commands that work on normal Combo and ListBoxes do not work on * "ComboLBox" controls. When using a control name in the Control functions, * you need to add a number to the end of the name to indicate which * control. For example, if there two controls listed called "MDIClient", * you would refer to these as "MDIClient1" and "MDIClient2". Use * AU3_Spy.exe to obtain a control's number. * * When using text instead of ClassName# in "Control" commands, be sure to * use the entire text of the control. Partial text will fail. * * @param title * The title of the window to access. * @param text * The text of the window to access. * @param control * The control to interact with. * @param index * The zero-based index of the item to retrieve. * @return Returns the item according to index in a ListBox or ComboBox. */ public static String getString(final String title, final String text, final String control, final int index) { String item = null; if (index >= 0) { HWND hWnd = getHandle_(title, text, control); if (hWnd != null) { boolean isComboBox = Win32.isComboBox(hWnd); boolean isListBox = Win32.isListBox(hWnd); if (isComboBox || isListBox) { int getItemLengthMessage = LB_GETTEXTLEN; int getItemMessage = LB_GETTEXT; if (isComboBox) { getItemLengthMessage = CB_GETLBTEXTLEN; getItemMessage = CB_GETLBTEXT; } // get item length int itemLength = Win32.user32.SendMessage(hWnd, getItemLengthMessage, index, 0); if (itemLength == 0) { item = ""; } else if (itemLength > 0) { // get item final CharBuffer buffer = CharBuffer .allocate(itemLength + 1); Win32.user32.SendMessage(hWnd, getItemMessage, new WPARAM(index), buffer); item = Native.toString(buffer.array()); } } } } return item; }
@Override public void setIcon (FileHandle iconCacheFolder, FileHandle icoFile, FileHandle pngFile) { //WinAPI can't read icon from JAR, needs copying to some other location FileHandle cachedIco = iconCacheFolder.child(icoFile.name()); if (cachedIco.exists() == false) icoFile.copyTo(cachedIco); try { HANDLE hImage = User32.INSTANCE.LoadImage(Kernel32.INSTANCE.GetModuleHandle(""), cachedIco.path(), WinUser.IMAGE_ICON, 0, 0, WinUser.LR_LOADFROMFILE); User32.INSTANCE.SendMessageW(User32.INSTANCE.GetActiveWindow(), User32.WM_SETICON, new WPARAM(User32.BIG_ICON), hImage); } catch (Exception e) { throw new IllegalStateException(e); } }
@Override public void update(float delta) { compWin.update(delta, window); if (run) { compWin.dispose(window); Container bottomBtns = new Container(0, 0, 200, 60); char[] name = new char[1024]; User32Ext.INSTANCE.GetWindowTextW(hwndWin, name, name.length); String title = Native.toString(name); Button btnClose = new Button(0, 0, 200, 30, "Close"); btnClose.setPreicon(Theme.ICON_CHROME_CLOSE); btnClose.setPreiconSize(12); btnClose.setOnButtonPress(() -> { User32.INSTANCE.PostMessage(this.hwndWin, WM_CLOSE, new WPARAM(), new LPARAM()); TaskManager.addTask(() -> window.setVisible(false)); }); Button btnOpen = new Button(0, 30, 200, 30, title); btnOpen.setOnButtonPress(() -> { char[] classNameC = new char[128]; User32.INSTANCE.GetClassName(hwndWin, classNameC, classNameC.length); String className = Native.toString(classNameC); if (!className.equals("ApplicationFrameWindow")) try { new ProcessBuilder(WindowUtils.getProcessFilePath(hwndWin), "").start(); } catch (IOException e) { e.printStackTrace(); } TaskManager.addTask(() -> window.setVisible(false)); }); bottomBtns.addComponent(btnClose); bottomBtns.addComponent(btnOpen); Image icon = new Image(13, 38, 16, 16, Util.getIcon(hwndWin, window), true); bottomBtns.addComponent(icon); compWin.addComponent(bottomBtns); Container tasks = new Container(-20, 0, 220, 140); tasks.setLayout(new FlowLayout(Direction.DOWN, 0, 10)); for (int i = 0; i < 4; i++) { Button t = new Button(0, 0, 220, 30, "Task " + i); t.setWindowAlignment(Alignment.LEFT_TOP); t.setAlignment(Alignment.RIGHT_BOTTOM); tasks.addComponent(t); } compWin.addComponent(tasks); TaskManager.addTask(() -> window.setVisible(true)); run = false; } }
public LowLevelMouseProc hookTheMouse() { return new LowLevelMouseProc() { public LRESULT callback(int nCode, WPARAM wParam, MOUSEHOOKSTRUCT info) { LRESULT result = USER32INST.CallNextHookEx(hhk, nCode, wParam, new WinDef.LPARAM(Pointer.nativeValue(info.getPointer()))); if (nCode >= 0) { int action = wParam.intValue(); // System.out.println(action); switch (action) { case WM_LBUTTONDOWN: // do stuff break; case WM_RBUTTONDOWN: WindowsXPMouse.action.run(); break; case WM_MBUTTONDOWN: // do other stuff break; case WM_LBUTTONUP: WindowsXPMouse.action.run(); break; case WM_MOUSEMOVE: break; default: break; } /**************************** DO NOT CHANGE, this code unhooks mouse *********************************/ if (threadFinish == true) { // System.out.println("post quit"); USER32INST.PostQuitMessage(0); } /*************************** END OF UNCHANGABLE *******************************************************/ } return result; } }; }
/** * Sends {@code WM_CLOSE} to the specified Windows {@link Process}. * * @param processInfo the {@link ProcessInfo} referencing the * {@link Process} to send to. * @return {@code true} if {@code WM_CLOSE} was sent, {@code false} * otherwise. */ protected boolean stopWindowsProcessWMClosed(@Nonnull ProcessInfo processInfo) { if (LOGGER.isTraceEnabled()) { LOGGER.trace( "Attempting to stop timed out process \"{}\" ({}) with WM_CLOSE", processInfo.getName(), processInfo.getPID() ); } HANDLE hProc = Kernel32.INSTANCE.OpenProcess( Kernel32.SYNCHRONIZE | Kernel32.PROCESS_TERMINATE, false, processInfo.getPID() ); if (hProc == null) { if (LOGGER.isTraceEnabled()) { LOGGER.trace( "Failed to get Windows handle for process \"{}\" ({}) during WM_CLOSE", processInfo.getName(), processInfo.getPID() ); } return false; } final Memory posted = new Memory(1); posted.setByte(0, (byte) 0); Memory dwPID = new Memory(4); dwPID.setInt(0, processInfo.getPID()); User32.INSTANCE.EnumWindows(new WNDENUMPROC() { @Override public boolean callback(HWND hWnd, Pointer data) { IntByReference dwID = new IntByReference(); User32.INSTANCE.GetWindowThreadProcessId(hWnd, dwID); if (dwID.getValue() == data.getInt(0)) { User32.INSTANCE.PostMessage(hWnd, User32.WM_CLOSE, new WPARAM(0), new LPARAM(0)); posted.setByte(0, (byte) 1); } return true; } }, dwPID); Kernel32.INSTANCE.CloseHandle(hProc); if (LOGGER.isTraceEnabled()) { if (posted.getByte(0) > 0) { LOGGER.trace( "WM_CLOSE sent to process \"{}\" ({}) with PostMessage", processInfo.getName(), processInfo.getPID() ); } else { LOGGER.trace( "Can't find any Windows belonging to process \"{}\" ({}), unable to send WM_CLOSE", processInfo.getName(), processInfo.getPID() ); } } return posted.getByte(0) > 0; }
public LRESULT callback(int nCode, WPARAM wParam, LPARAM lParam) { System.err.println("callback bbbnhkilhjkibh nCode: " + nCode); return new LRESULT(0); }
/** * Checks to see if the item expanded. * * @param title * The title of the window to access. * @param text * The text of the window to access. * @param control * The control to interact with. * @param item * The "item" parameter is a string-based parameter that is used * to reference a particular treeview item using a combination of * text and indices. Indices are 0-based. For example:<br/> * Heading1<br/> * ----> H1SubItem1<br/> * ----> H1SubItem2<br/> * ----> H1SubItem3<br/> * ----> ----> H1S1SubItem1<br/> * Heading2<br/> * Heading3<br/> * * Each "level" is separated by |. An index is preceded with #. * Examples:<br/> * * <table> * <thead> * <tr> * <td>Item</td> * <td>Item Reference</td> * </tr> * </thead> * <tr> * <td>Heading2</td> * <td>"Heading2" or "#1"</td> * </tr> * <tr> * <td>H1SubItem2</td> * <td>"Heading1|H1SubItem2" or "#0|#1"</td> * </tr> * <tr> * <td>H1S1SubItem1</td> * <td>"Heading1|H1SubItem3|H1S1SubItem1" or "#0|#2|#0"</td> * </tr> * </table> * * References can also be mixed like "Heading1|#1". * @return Returns true if item is expanded, otherwise return false. */ public static boolean isExpanded(final String title, final String text, final String control, final String item) { boolean expanded = false; HWND hWnd = Control.getHandle_(title, text, control); if (hWnd != null) { HWND itemHWND = getHandle(title, text, control, item); if (itemHWND != null) { TVITEM treeViewItem = new TVITEM(); treeViewItem.mask = new UINT(TVIF_STATE); treeViewItem.hItem = (int) Pointer.nativeValue(itemHWND .getPointer()); Win32.user32.SendMessage(hWnd, TVM_GETITEMW, new WPARAM(0), treeViewItem); expanded = ((treeViewItem.state.intValue() & TVIS_EXPANDED) != 0); } } return expanded; }
public void initKeyHook() { thread = new Thread(new Runnable() { @Override public void run() { final User32 lib = User32.INSTANCE; HMODULE hMod = Kernel32.INSTANCE.GetModuleHandle(null); keyboardHook = new LowLevelKeyboardProc() { public LRESULT callback(int nCode, WPARAM wParam, KBDLLHOOKSTRUCT info) { if (nCode >= 0) { switch (wParam.intValue()) { // case WinUser.WM_KEYUP: case WinUser.WM_KEYDOWN: // case WinUser.WM_SYSKEYUP: case WinUser.WM_SYSKEYDOWN: // do active userActive(); } } return lib.CallNextHookEx(hhk, nCode, wParam, info.getPointer()); } }; hhk = lib.SetWindowsHookEx(WinUser.WH_KEYBOARD_LL, keyboardHook, hMod, 0); // This bit never returns from GetMessage int result; MSG msg = new MSG(); while ((result = lib.GetMessage(msg, null, 0, 0)) != 0) { if (result == -1) { System.err.println("error in get message"); break; } else { System.err.println("got message"); lib.TranslateMessage(msg); lib.DispatchMessage(msg); } } lib.UnhookWindowsHookEx(hhk); } }); thread.start(); }
/** * @param hwnd [in] Type: HWND * * A handle to the window. * * @param uMsg [in] Type: UINT * * The message. * * For lists of the system-provided messages, see System-Defined * Messages. * * @param wParam [in] Type: WPARAM * * Additional message information. The contents of this parameter depend * on the value of the uMsg parameter. * * @param lParam [in] Type: LPARAM * * Additional message information. The contents of this parameter depend * on the value of the uMsg parameter. * * @return the lresult */ LRESULT callback(HWND hwnd, int uMsg, WPARAM wParam, LPARAM lParam);
/** * An application-defined function that processes messages sent * to a window. * * @param hwnd A handle to the window. * @param uMsg The message. * @param wParam Additional message information. * @param lParam Additional message information. * @return The result of the message processing and depends on * the message sent */ LRESULT callback(HWND hwnd, int uMsg, WPARAM wParam, LPARAM lParam);
LRESULT DefWindowProc(HWND hwnd, int msg, WPARAM wp, LPARAM lp);
LRESULT callback(HWND hwnd, int msg, WPARAM wp, LPARAM lp);
void SendMessage(HWND nextViewer, int uMsg, WPARAM wParam, LPARAM lParam);
public LRESULT SendMessage(HWND hwnd, int msg, WPARAM wParam, LPARAM lParam);
public boolean SendNotifyMessage(HWND hwnd, int msg, WPARAM wParam, LPARAM lParam);
LRESULT callback(int nCode, WPARAM wParam, MOUSEHOOKSTRUCT lParam);
public LRESULT callback(HWND hwnd, int msg, WPARAM wp, LPARAM lp);
LRESULT callback(int nCode, WPARAM wParam, KBDLLHOOKSTRUCT lParam);
LPARAM SendMessageW (HWND hWnd, int msg, WPARAM wParam, HANDLE lParam);