Java JNA Postmessage不起作用

时间:2014-08-07 08:22:34

标签: java jna postmessage user32

我正在尝试使用Postmessage将键击发送到特定窗口,但它似乎对我不起作用。这是我的代码

import com.sun.jna.platform.win32.User32;
import com.sun.jna.platform.win32.WinDef.HWND;
import com.sun.jna.platform.win32.WinDef.LPARAM;
import com.sun.jna.platform.win32.WinDef.WPARAM;


public class keystroke {

   public static void main(String[] args){

      int WM_KEYDOWN = 0x0100;
      int WM_KEYUP = 0x0101;
      int WM_CHAR = 0x0102;

      int VK_A = 0x41;


      WPARAM wPARAM = new WPARAM(VK_A);
      LPARAM lPARAM = new LPARAM(0);

      HWND hwnd = User32.INSTANCE.FindWindow(null, "Notepad"); // window title

      User32.INSTANCE.ShowWindow(hwnd, 9); // SW_RESTOR
      User32.INSTANCE.SetForegroundWindow(hwnd); // bring to front

      User32.INSTANCE.SetFocus(hwnd);

      User32.INSTANCE.PostMessage(hwnd, WM_CHAR, wPARAM, lPARAM);

     }
}

当我改为

时,它也无效
  User32.INSTANCE.PostMessage(hwnd, WM_KEYDOWN, wPARAM, lPARAM);
  User32.INSTANCE.PostMessage(hwnd, WM_KEYUP, wPARAM, lPARAM);

0 个答案:

没有答案