当前位置: 首页>>代码示例>>Java>>正文


Java WinDef类代码示例

本文整理汇总了Java中com.sun.jna.platform.win32.WinDef的典型用法代码示例。如果您正苦于以下问题:Java WinDef类的具体用法?Java WinDef怎么用?Java WinDef使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


WinDef类属于com.sun.jna.platform.win32包,在下文中一共展示了WinDef类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doKeyPress

import com.sun.jna.platform.win32.WinDef; //导入依赖的package包/类
@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);
    }
}
 
开发者ID:paspiz85,项目名称:nanobot,代码行数:21,代码来源:BlueStacksWinPlatform.java

示例2: while

import com.sun.jna.platform.win32.WinDef; //导入依赖的package包/类
/**
 * Finds the given process in the process list.
 *
 * @param processEntry The process entry.
 * @param filenamePattern pattern matching the filename of the process.
 * @return The found process entry.
 */
public static boolean findProcessEntry
                (final Tlhelp32.PROCESSENTRY32.ByReference processEntry,
                 final Pattern filenamePattern) {
    Kernel32 kernel32 = Native.loadLibrary(Kernel32.class, W32APIOptions.UNICODE_OPTIONS);

    WinNT.HANDLE snapshot = kernel32.CreateToolhelp32Snapshot(Tlhelp32.TH32CS_SNAPPROCESS, new WinDef.DWORD(0));

    boolean found = false;

    try {
        while (kernel32.Process32Next(snapshot, processEntry)) {
            String fname = Native.toString(processEntry.szExeFile);

            if (fname != null && filenamePattern.matcher(fname).matches()) {
                found = true;
                break;
            }
        }
    } finally {
        kernel32.CloseHandle(snapshot);
    }

    return found;
}
 
开发者ID:mmarquee,项目名称:ui-automation,代码行数:32,代码来源:Utils.java

示例3: capture

import com.sun.jna.platform.win32.WinDef; //导入依赖的package包/类
/**
 * Captures the window.
 *
 * @param hwnd The window to capture.
 * @param filename Name to save the output into.
 * @throws AWTException Robot exception.
 * @throws IOException IO Exception.
 */
public static void capture(final WinDef.HWND hwnd,
                           final String filename)
        throws AWTException, IOException, Win32Exception {
    ensureWinApiInstances();
    
    WinDef.RECT rect = new WinDef.RECT();

    if (!user32.GetWindowRect(hwnd, rect)) {
        throw new Win32Exception(kernel32.GetLastError());
    }

    Rectangle rectangle = new Rectangle(rect.left, rect.top, rect.right -rect.left, rect.bottom -rect.top);

    BufferedImage image = new Robot().createScreenCapture(rectangle);

    ImageIO.write(image, "png", new File(filename));
}
 
开发者ID:mmarquee,项目名称:ui-automation,代码行数:26,代码来源:Utils.java

示例4: quit

import com.sun.jna.platform.win32.WinDef; //导入依赖的package包/类
/**
 * Quits the process.
 *
 * @param titlePattern a pattern matching the title of the window of the process to quit
 */
public void quit(final Pattern titlePattern) {
    if (user32 == null) {
        user32 = User32.INSTANCE;
    }

    final WinDef.HWND handle = Utils.findWindow(null, titlePattern);

    if (handle != null) {
        Utils.quitProcess(handle);
    }
}
 
开发者ID:mmarquee,项目名称:ui-automation,代码行数:17,代码来源:AutomationApplication.java

示例5: testStartProcess_Starts_Notepad

import com.sun.jna.platform.win32.WinDef; //导入依赖的package包/类
@Test
public void testStartProcess_Starts_Notepad() {
    try {
        Utils.startProcess("notepad.exe");

        this.andRest();

        WinDef.HWND hwnd = User32.INSTANCE.FindWindow(null, getLocal("notepad.title"));

        assertTrue("startProcess - no process", hwnd != null);
    } catch (IOException io) {
        assertTrue("startProcess: " + io.getMessage(), false);
    }

    assertTrue("startProcess", true);
}
 
开发者ID:mmarquee,项目名称:ui-automation,代码行数:17,代码来源:UtilsTest.java

示例6: testQuitProcess_Quits_Notepad

import com.sun.jna.platform.win32.WinDef; //导入依赖的package包/类
@Test
public void testQuitProcess_Quits_Notepad() {
    try {
        Utils.startProcess("notepad.exe");

        WinDef.HWND hwnd = User32.INSTANCE.FindWindow(null, getLocal("notepad.title"));

        if (hwnd != null) {
            Utils.quitProcess(hwnd);
        }
    } catch (IOException io) {
        assertTrue("quitProcess: " + io.getMessage(), false);
    }

    assertTrue("quitProcess", true);
}
 
开发者ID:mmarquee,项目名称:ui-automation,代码行数:17,代码来源:UtilsTest.java

示例7: testCloseWindow_Closes_Notepad

import com.sun.jna.platform.win32.WinDef; //导入依赖的package包/类
@Test
public void testCloseWindow_Closes_Notepad() {
    try {
        Utils.startProcess("notepad.exe");

        WinDef.HWND hwnd = User32.INSTANCE.FindWindow(null, getLocal("notepad.title"));

        if (hwnd != null) {
            Utils.closeWindow(hwnd);
        }
    } catch (IOException io) {
        assertTrue("quitProcess: " + io.getMessage(), false);
    }

    assertTrue("quitProcess", true);
}
 
开发者ID:mmarquee,项目名称:ui-automation,代码行数:17,代码来源:UtilsTest.java

示例8: test_windowHandle_Calls_currentPropertyValue_From_Window

import com.sun.jna.platform.win32.WinDef; //导入依赖的package包/类
@Test
public void test_windowHandle_Calls_currentPropertyValue_From_Window() throws Exception {
    doAnswer(invocation -> {
        Object[] args = invocation.getArguments();
        Object reference = (Object)args[0];

        reference = 1245;

        return 1234;
    }).when(element).getPropertyValue(anyInt());

    IUIAutomation mocked_automation = Mockito.mock(IUIAutomation.class);
    UIAutomation instance = new UIAutomation(mocked_automation);

    AutomationWindow wndw = new AutomationWindow(
            new ElementBuilder(element).window(window).itemContainer(container).automation(instance));

    WinDef.HWND handle = wndw.getNativeWindowHandle();

    verify(element, atLeastOnce()).getPropertyValue(anyInt());
}
 
开发者ID:mmarquee,项目名称:ui-automation,代码行数:22,代码来源:AutomationWindowTest2.java

示例9: main

import com.sun.jna.platform.win32.WinDef; //导入依赖的package包/类
public static void main(String[] args) {
    final User32 user32 = User32.INSTANCE;
    user32.EnumWindows(new WinUser.WNDENUMPROC() {
        int count = 0;
        @Override
        public boolean callback(WinDef.HWND hwnd, Pointer pointer) {
            byte[] windowText = new byte[512];
            byte[] className = new byte[512];
            user32.GetWindowTextA(hwnd, windowText, 512);
            user32.GetClassNameA(hwnd, className, 512);
            String title = Native.toString(windowText);
            String classN = Native.toString(className);

            // get rid of this if block if you want all windows regardless of whether
            // or not they have text
            if (title.isEmpty()) {
                return true;
            }

            System.out.println("Title: " + title + " Class name: " + classN);
            return true;
        }
    },null);
}
 
开发者ID:Exslims,项目名称:MercuryTrade,代码行数:25,代码来源:Test.java

示例10: isMassEffect3Running

import com.sun.jna.platform.win32.WinDef; //导入依赖的package包/类
/**
 * Checks if MassEffect3.exe is currently running. Uses native code.
 * 
 * @return
 */
public static boolean isMassEffect3Running() {
	try {
		Kernel32 kernel32 = (Kernel32) Native.loadLibrary(Kernel32.class, W32APIOptions.UNICODE_OPTIONS);
		Tlhelp32.PROCESSENTRY32.ByReference processEntry = new Tlhelp32.PROCESSENTRY32.ByReference();
		boolean result = false;
		WinNT.HANDLE snapshot = kernel32.CreateToolhelp32Snapshot(Tlhelp32.TH32CS_SNAPPROCESS, new WinDef.DWORD(0));
		try {
			while (kernel32.Process32Next(snapshot, processEntry)) {
				if ("MassEffect3.exe".toUpperCase().equals(Native.toString(processEntry.szExeFile).toUpperCase())) {
					result = true;
					break;
				}
			}
		} finally {
			kernel32.CloseHandle(snapshot);
		}
		ModManager.debugLogger.writeMessage("Mass Effect 3 is " + (result ? "" : "not ") + "currently running.");
		return result;
	} catch (Throwable t) {
		ModManager.debugLogger.writeErrorWithException("Critical native access exception: ", t);
		ModManager.debugLogger.writeError("Mod Manager will report that the game is not running to continue normal operations.");
		return false;
	}
}
 
开发者ID:Mgamerz,项目名称:me3modmanager,代码行数:30,代码来源:ModManager.java

示例11: pressKeys

import com.sun.jna.platform.win32.WinDef; //导入依赖的package包/类
public void pressKeys(final List<KeyboardKey> keys) {
    if (keys.isEmpty()) {
        return;
    }

    final WinUser.INPUT input = new WinUser.INPUT();
    final WinUser.INPUT[] inputs = (WinUser.INPUT[]) input.toArray(keys.size() * 2);

    final ListIterator<KeyboardKey> iterator = keys.listIterator();
    int index = 0;
    while (iterator.hasNext()) {
        setKeyDown(inputs[index], iterator.next());
        index++;
    }
    while (iterator.hasPrevious()) {
        setKeyUp(inputs[index], iterator.previous());
        index++;
    }

    user32.SendInput(new WinDef.DWORD(inputs.length), inputs, inputs[0].size());
}
 
开发者ID:msiedlarek,项目名称:winthing,代码行数:22,代码来源:KeyboardService.java

示例12: reloadSessions

import com.sun.jna.platform.win32.WinDef; //导入依赖的package包/类
private void reloadSessions() {
   WinDef.HWND hwnd = new WinDef.HWND(Native.getWindowPointer(MainFrame.this));
   WinDef.HMENU systemMenu = user32.GetSystemMenu(hwnd, new WinDef.BOOL(0));
   if (sessionsSeparatorPos > 0) {
      for (int i = sessionsSeparatorPos; i >= 0; i--) {
         user32.DeleteMenu(systemMenu, new WinDef.UINT(i), User32.MF_BYPOSITION);
      }
   }
   mapCustomMenuHandlers.clear();
   sessionsSeparatorPos = 0;
   try {
      File kittyHomeFile = new File(kittyHome);
      if (kittyHomeFile.isDirectory()) {
         for (File sessions : kittyHomeFile.listFiles()) {
            if (sessions.isDirectory() && "Sessions".equals(sessions.getName())) {
               sessionsSeparatorPos = loadSessions(systemMenu, mapCustomMenuHandlers, "", sessions, 0);
               if (sessionsSeparatorPos > 0) {
                  WinUtil.InsertMenuSeparator(systemMenu, sessionsSeparatorPos, ++CUSTOM_MENU_LAST_ID);
               }
            }
         }
      }
   } catch (UnsupportedEncodingException ex) {
      throw new RuntimeException("Error reloading esssions!", ex);
   }
}
 
开发者ID:vanjadardic,项目名称:KiTTY2,代码行数:27,代码来源:MainFrame.java

示例13: registerAllHotKeys

import com.sun.jna.platform.win32.WinDef; //导入依赖的package包/类
private void registerAllHotKeys() // must register hot keys in the same thread that is watching for hotkey messages
{
	//System.out.println("registering hotkeys");
	for (TargetKeyPress tkp : KeyboardHook.targetList) {
		//BOOL WINAPI RegisterHotKey(HWND hWnd, int id, UINT fsModifiers, UINT vk);
		int modifiers = User32.MOD_NOREPEAT;
		if (tkp.withShift)
			modifiers = modifiers | User32.MOD_SHIFT;
		if (tkp.withCtrl)
			modifiers = modifiers | User32.MOD_CONTROL;
		if (tkp.withAlt)
			modifiers = modifiers | User32.MOD_ALT;
		//System.out.println("RegisterHotKey " + tkp.idNumber + "," + modifiers + ", " + tkp.targetKeyCode);
		
		if (!User32.INSTANCE.RegisterHotKey(new WinDef.HWND(Pointer.NULL), tkp.idNumber, modifiers, tkp.targetKeyCode))
		{
            System.out.println("Couldn't register hotkey " + tkp.targetKeyCode);
		}
	}
}
 
开发者ID:Synthuse,项目名称:synthuse-src,代码行数:21,代码来源:KeyboardHook.java

示例14: extractExeIcon

import com.sun.jna.platform.win32.WinDef; //导入依赖的package包/类
public static BufferedImage extractExeIcon(String fullExeFile, int index, boolean large) {
    PointerByReference iconsLargeRef = new PointerByReference();
    PointerByReference iconsSmallRef = new PointerByReference();
    int cnt = Shell32.INSTANCE.ExtractIconEx(fullExeFile, index, iconsLargeRef, iconsSmallRef, new WinDef.UINT(1)).intValue();
    if (cnt == 0) {
        return null;
    }
    Pointer iconsLarge = iconsLargeRef.getPointer();
    Pointer iconsSmall = iconsSmallRef.getPointer();

    WinDef.HICON icon;
    if (large) {
        icon = new WinDef.HICON(iconsLarge.getPointer(0));
    } else {
        icon = new WinDef.HICON(iconsSmall.getPointer(0));
    }

    BufferedImage ic = iconToImage(icon);

    User32.INSTANCE.DestroyIcon(icon);
    return ic;
}
 
开发者ID:jindrapetrik,项目名称:jpexs-decompiler,代码行数:23,代码来源:Win32ProcessTools.java

示例15: findChildWindowByText

import com.sun.jna.platform.win32.WinDef; //导入依赖的package包/类
public static WindowHolder findChildWindowByText(WindowHolder parenWindow, String text) {
	WinDef.DWORD fiveButton = new WinDef.DWORD(Long.parseLong(text));
	WinDef.HWND fiveButtonWnd = user32.GetWindow(parenWindow.getParentWindow(), fiveButton);
	if (fiveButtonWnd == null) {
		return null;
	}
	WINDOWINFO pwi = new WINDOWINFO();
	System.out.println(user32.GetWindowInfo(fiveButtonWnd, pwi));
	WindowHolder windowHolder = new WindowHolder(fiveButtonWnd, pwi);
	return windowHolder;
}
 
开发者ID:frolovm,项目名称:poker-bot,代码行数:12,代码来源:User32Utils.java


注:本文中的com.sun.jna.platform.win32.WinDef类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。