2017-09-25 9 views
0

내 프로젝트 코드를 아래 예제로 압축하여 내 문제를 표시했습니다.내 JNA SendInput() 호출에 결함이 있습니까?

예제/스 니펫은 herehere의 개념을 참조합니다. 콘솔 출력에 4 개의 이벤트가 전송되었습니다. 그래서 메모장의 출력이 "12"가 될 것으로 예상했지만 메모장에서 "1"만 볼 수 있습니다. 누군가 올바른 방향으로 나를 가리킬 수 있습니까? jar 파일은 Windows 10 x64에서 빌드되고 실행됩니다.

import com.sun.jna.Structure; 
import com.sun.jna.platform.win32.WTypes.BSTR; 
import com.sun.jna.platform.win32.WinUser; 
import com.sun.jna.platform.win32.WinDef; 
import com.sun.jna.platform.win32.BaseTSD; 
import com.sun.jna.platform.win32.User32; 

public class App { 

    public static void main(String[] args) 
    { 
     int KEYEVENT_SCANCODE = 0x0008; 
     int KEYEVENT_UP = 0x0002; 

     WinUser.INPUT[] inputArray = (WinUser.INPUT[]) new WinUser.INPUT().toArray(4); 

     inputArray[0].type = new WinDef.DWORD(WinUser.INPUT.INPUT_KEYBOARD); 
     inputArray[0].input.setType("ki"); 
     inputArray[0].input.ki.time = new WinDef.DWORD(0); 
     inputArray[0].input.ki.wVk = new WinDef.WORD(0); //using scancodes instead 
     inputArray[0].input.ki.dwExtraInfo = new BaseTSD.ULONG_PTR(0); 
     inputArray[0].input.ki.dwFlags = new WinDef.DWORD(KEYEVENT_SCANCODE); 
     inputArray[0].input.ki.wScan = new WinDef.WORD(0x01); 

     inputArray[1].type = new WinDef.DWORD(WinUser.INPUT.INPUT_KEYBOARD); 
     inputArray[1].input.setType("ki"); 
     inputArray[1].input.ki.time = new WinDef.DWORD(0); 
     inputArray[1].input.ki.wVk = new WinDef.WORD(0); //using scancodes instead 
     inputArray[1].input.ki.dwExtraInfo = new BaseTSD.ULONG_PTR(0); 
     inputArray[1].input.ki.dwFlags = new WinDef.DWORD(KEYEVENT_SCANCODE | KEYEVENT_UP); 
     inputArray[1].input.ki.wScan = new WinDef.WORD(0x01); 

     inputArray[2].type = new WinDef.DWORD(WinUser.INPUT.INPUT_KEYBOARD); 
     inputArray[2].input.setType("ki"); 
     inputArray[2].input.ki.time = new WinDef.DWORD(0); 
     inputArray[2].input.ki.wVk = new WinDef.WORD(0); //using scancodes instead 
     inputArray[2].input.ki.dwExtraInfo = new BaseTSD.ULONG_PTR(0); 
     inputArray[2].input.ki.dwFlags = new WinDef.DWORD(KEYEVENT_SCANCODE); 
     inputArray[2].input.ki.wScan = new WinDef.WORD(0x02); 

     inputArray[3].type = new WinDef.DWORD(WinUser.INPUT.INPUT_KEYBOARD); 
     inputArray[3].input.setType("ki"); 
     inputArray[3].input.ki.time = new WinDef.DWORD(0); 
     inputArray[3].input.ki.wVk = new WinDef.WORD(0); //using scancodes instead 
     inputArray[3].input.ki.dwExtraInfo = new BaseTSD.ULONG_PTR(0); 
     inputArray[3].input.ki.dwFlags = new WinDef.DWORD(KEYEVENT_SCANCODE | KEYEVENT_UP); 
     inputArray[3].input.ki.wScan = new WinDef.WORD(0x02); 

     System.out.println("Make sure notepad is in focus..."); 
     try { Thread.sleep(7000); } catch (Throwable ex) { System.out.println("Interrupted"); } 

     WinDef.DWORD sentInputs = User32.INSTANCE.SendInput( 
      new WinDef.DWORD(inputArray.length), 
       inputArray, 
       inputArray[0].size() 
     ); 

     System.out.println("Sent Input Count: " + sentInputs.intValue()); 
    } 
} 

콘솔 출력 :

E : \ SKGDE \ 내 - 응용 프로그램 \ 대상> 자바 -jar 내-응용 프로그램-1.0-SNAPSHOT - 항아리 -와 - dependencies.jar

만들기 반드시 메모장 ... 초점이

보낸 입력 개수 : 4

E : \ SKGDE \ 내 - 응용 프로그램 \ 대상>

답변

0

메모장은 잘못된 스캔 코드를 보내고 있기 때문에 "1"이 아닌 "12"만을 표시합니다. 여기에 먼저 KEY (0x01로) ESC에 대한 스캔 코드를 전송하는 다음 1 KEY (는 0x02)에 대한 스캔 코드를 전송.

먼저 다음 1 KEY (는 0x02) 및 2 KEY (은 0x03)에 대한 스캔 코드를 전송한다

사용 ScanCode.java, 당신은 스캔을 기억 해달라고 있도록 코드.

public interface ScanCode { 

public static final int DIK_ESCAPE   =0x01; 
public static final int DIK_1    =0x02; 
public static final int DIK_2    =0x03; 
public static final int DIK_3    =0x04; 
public static final int DIK_4    =0x05; 
public static final int DIK_5    =0x06; 
public static final int DIK_6    =0x07; 
public static final int DIK_7    =0x08; 
public static final int DIK_8    =0x09; 
public static final int DIK_9    =0x0A; 
public static final int DIK_0    =0x0B; 
public static final int DIK_MINUS   =0x0C; /* - on main keyboard */ 
public static final int DIK_EQUALS   =0x0D; 
public static final int DIK_BACK   =0x0E; /* backspace */ 
public static final int DIK_TAB    =0x0F; 
public static final int DIK_Q    =0x10; 
public static final int DIK_W    =0x11; 
public static final int DIK_E    =0x12; 
public static final int DIK_R    =0x13; 
public static final int DIK_T    =0x14; 
public static final int DIK_Y    =0x15; 
public static final int DIK_U    =0x16; 
public static final int DIK_I    =0x17; 
public static final int DIK_O    =0x18; 
public static final int DIK_P    =0x19; 
public static final int DIK_LBRACKET  =0x1A; 
public static final int DIK_RBRACKET  =0x1B; 
public static final int DIK_RETURN   =0x1C; /* Enter on main keyboard */ 
public static final int DIK_LCONTROL  =0x1D; 
public static final int DIK_A    =0x1E; 
public static final int DIK_S    =0x1F; 
public static final int DIK_D    =0x20; 
public static final int DIK_F    =0x21; 
public static final int DIK_G    =0x22; 
public static final int DIK_H    =0x23; 
public static final int DIK_J    =0x24; 
public static final int DIK_K    =0x25; 
public static final int DIK_L    =0x26; 
public static final int DIK_SEMICOLON  =0x27; 
public static final int DIK_APOSTROPHE  =0x28; 
public static final int DIK_GRAVE   =0x29; /* accent grave */ 
public static final int DIK_LSHIFT   =0x2A; 
public static final int DIK_BACKSLASH  =0x2B; 
public static final int DIK_Z    =0x2C; 
public static final int DIK_X    =0x2D; 
public static final int DIK_C    =0x2E; 
public static final int DIK_V    =0x2F; 
public static final int DIK_B    =0x30; 
public static final int DIK_N    =0x31; 
public static final int DIK_M    =0x32; 
public static final int DIK_COMMA   =0x33; 
public static final int DIK_PERIOD   =0x34; /* . on main keyboard */ 
public static final int DIK_SLASH   =0x35; /*/on main keyboard */ 
public static final int DIK_RSHIFT   =0x36; 
public static final int DIK_MULTIPLY  =0x37; /* * on numeric keypad */ 
public static final int DIK_LMENU   =0x38; /* left Alt */ 
public static final int DIK_SPACE   =0x39; 
public static final int DIK_CAPITAL   =0x3A; 
public static final int DIK_F1    =0x3B; 
public static final int DIK_F2    =0x3C; 
public static final int DIK_F3    =0x3D; 
public static final int DIK_F4    =0x3E; 
public static final int DIK_F5    =0x3F; 
public static final int DIK_F6    =0x40; 
public static final int DIK_F7    =0x41; 
public static final int DIK_F8    =0x42; 
public static final int DIK_F9    =0x43; 
public static final int DIK_F10    =0x44; 
public static final int DIK_NUMLOCK   =0x45; 
public static final int DIK_SCROLL   =0x46; /* Scroll Lock */ 
public static final int DIK_NUMPAD7   =0x47; 
public static final int DIK_NUMPAD8   =0x48; 
public static final int DIK_NUMPAD9   =0x49; 
public static final int DIK_SUBTRACT  =0x4A; /* - on numeric keypad */ 
public static final int DIK_NUMPAD4   =0x4B; 
public static final int DIK_NUMPAD5   =0x4C; 
public static final int DIK_NUMPAD6   =0x4D; 
public static final int DIK_ADD    =0x4E; /* + on numeric keypad */ 
public static final int DIK_NUMPAD1   =0x4F; 
public static final int DIK_NUMPAD2   =0x50; 
public static final int DIK_NUMPAD3   =0x51; 
public static final int DIK_NUMPAD0   =0x52; 
public static final int DIK_DECIMAL   =0x53; /* . on numeric keypad */ 
public static final int DIK_OEM_102   =0x56; /* <> or \| on RT 102-key keyboard (Non-U.S.) */ 
public static final int DIK_F11    =0x57; 
public static final int DIK_F12    =0x58; 
public static final int DIK_F13    =0x64; /*      (NEC PC98) */ 
public static final int DIK_F14    =0x65; /*      (NEC PC98) */ 
public static final int DIK_F15    =0x66; /*      (NEC PC98) */ 
public static final int DIK_KANA   =0x70; /* (Japanese keyboard)   */ 
public static final int DIK_ABNT_C1   =0x73; /* /? on Brazilian keyboard */ 
public static final int DIK_CONVERT   =0x79; /* (Japanese keyboard)   */ 
public static final int DIK_NOCONVERT  =0x7B; /* (Japanese keyboard)   */ 
public static final int DIK_YEN    =0x7D; /* (Japanese keyboard)   */ 
public static final int DIK_ABNT_C2   =0x7E; /* Numpad . on Brazilian keyboard */ 
public static final int DIK_NUMPADEQUALS =0x8D; /* = on numeric keypad (NEC PC98) */ 
public static final int DIK_PREVTRACK  =0x90; /* Previous Track (DIK_CIRCUMFLEX on Japanese keyboard) */ 
public static final int DIK_AT    =0x91; /*      (NEC PC98) */ 
public static final int DIK_COLON   =0x92; /*      (NEC PC98) */ 
public static final int DIK_UNDERLINE  =0x93; /*      (NEC PC98) */ 
public static final int DIK_KANJI   =0x94; /* (Japanese keyboard)   */ 
public static final int DIK_STOP   =0x95; /*      (NEC PC98) */ 
public static final int DIK_AX    =0x96; /*      (Japan AX) */ 
public static final int DIK_UNLABELED  =0x97; /*      (J3100) */ 
public static final int DIK_NEXTTRACK  =0x99; /* Next Track */ 
public static final int DIK_NUMPADENTER  =0x9C; /* Enter on numeric keypad */ 
public static final int DIK_RCONTROL  =0x9D; 
public static final int DIK_MUTE   =0xA0; /* Mute */ 
public static final int DIK_CALCULATOR  =0xA1; /* Calculator */ 
public static final int DIK_PLAYPAUSE  =0xA2; /* Play/Pause */ 
public static final int DIK_MEDIASTOP  =0xA4; /* Media Stop */ 
public static final int DIK_VOLUMEDOWN  =0xAE; /* Volume - */ 
public static final int DIK_VOLUMEUP  =0xB0; /* Volume + */ 
public static final int DIK_WEBHOME   =0xB2; /* Web home */ 
public static final int DIK_NUMPADCOMMA  =0xB3; /* , on numeric keypad (NEC PC98) */ 
public static final int DIK_DIVIDE   =0xB5; /*/on numeric keypad */ 
public static final int DIK_SYSRQ   =0xB7; 
public static final int DIK_RMENU   =0xB8; /* right Alt */ 
public static final int DIK_PAUSE   =0xC5; /* Pause */ 
public static final int DIK_HOME   =0xC7; /* Home on arrow keypad */ 
public static final int DIK_UP    =0xC8; /* UpArrow on arrow keypad */ 
public static final int DIK_PRIOR   =0xC9; /* PgUp on arrow keypad */ 
public static final int DIK_LEFT   =0xCB; /* LeftArrow on arrow keypad */ 
public static final int DIK_RIGHT   =0xCD; /* RightArrow on arrow keypad */ 
public static final int DIK_END    =0xCF; /* End on arrow keypad */ 
public static final int DIK_DOWN   =0xD0; /* DownArrow on arrow keypad */ 
public static final int DIK_NEXT   =0xD1; /* PgDn on arrow keypad */ 
public static final int DIK_INSERT   =0xD2; /* Insert on arrow keypad */ 
public static final int DIK_DELETE   =0xD3; /* Delete on arrow keypad */ 
public static final int DIK_LWIN   =0xDB; /* Left Windows key */ 
public static final int DIK_RWIN   =0xDC; /* Right Windows key */ 
public static final int DIK_APPS   =0xDD; /* AppMenu key */ 
public static final int DIK_POWER   =0xDE; /* System Power */ 
public static final int DIK_SLEEP   =0xDF; /* System Sleep */ 
public static final int DIK_WAKE   =0xE3; /* System Wake */ 
public static final int DIK_WEBSEARCH  =0xE5; /* Web Search */ 
public static final int DIK_WEBFAVORITES =0xE6; /* Web Favorites */ 
public static final int DIK_WEBREFRESH  =0xE7; /* Web Refresh */ 
public static final int DIK_WEBSTOP   =0xE8; /* Web Stop */ 
public static final int DIK_WEBFORWARD  =0xE9; /* Web Forward */ 
public static final int DIK_WEBBACK   =0xEA; /* Web Back */ 
public static final int DIK_MYCOMPUTER  =0xEB; /* My Computer */ 
public static final int DIK_MAIL   =0xEC; /* Mail */ 
public static final int DIK_MEDIASELECT  =0xED; /* Media Select */ 


}