Java Code Examples for org.sikuli.basics.Settings#AutoDetectKeyboardLayout

The following examples show how to use org.sikuli.basics.Settings#AutoDetectKeyboardLayout . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RobotDesktop.java    From SikuliX1 with MIT License 6 votes vote down vote up
private void doKeyRelease(int keyCode) {
  logRobot(stdAutoDelay, "KeyRelease: WaitForIdle: %s - Delay: %d");
  setAutoDelay(stdAutoDelay);
  // on Windows we detect the current layout in KeyboardLayout.
  // Since this layout is not compatible to AWT Robot, we have to use
  // the User32 API to simulate the key release
  if (Settings.AutoDetectKeyboardLayout && Settings.isWindows()) {
    int scanCode =  SXUser32.INSTANCE.MapVirtualKeyW(keyCode, 0);
    SXUser32.INSTANCE.keybd_event((byte)keyCode, (byte)scanCode, new WinDef.DWORD(WinUser.KEYBDINPUT.KEYEVENTF_KEYUP), new BaseTSD.ULONG_PTR(0));
  }else{
    keyRelease(keyCode);
  }

  if (stdAutoDelay == 0) {
    delay(stdDelay);
  }
  logRobot("KeyRelease: extended delay: %d", stdMaxElapsed);
}
 
Example 2
Source File: KeyboardLayout.java    From SikuliX1 with MIT License 6 votes vote down vote up
private static Map<Character, int[]> getCurrentLayout() {
  Map<Character, int[]> layout = DEFAULT_KEYBOARD_LAYOUT;

  if (Settings.AutoDetectKeyboardLayout && Settings.isWindows()) {
    int keyboarLayoutId = DEFAULT_KEYBOARD_LAYOUT_ID;
    HWND hwnd = SXUser32.INSTANCE.GetForegroundWindow();
    if (hwnd != null) {
      int threadID = SXUser32.INSTANCE.GetWindowThreadProcessId(hwnd, null);
      HKL keyboardLayoutHKL = SXUser32.INSTANCE.GetKeyboardLayout(threadID);
      if (keyboardLayoutHKL != null) {
        keyboarLayoutId = keyboardLayoutHKL.getLanguageIdentifier();
      }
    }

    synchronized(LAYOUTS) {
      layout = LAYOUTS.get(keyboarLayoutId);

      if (layout == null) {
        layout = buildWindowsLayout(keyboarLayoutId);
        LAYOUTS.put(keyboarLayoutId, layout);
      }
    }
  }
  return layout;
}
 
Example 3
Source File: RobotDesktop.java    From SikuliX1 with MIT License 5 votes vote down vote up
private void doKeyPress(int keyCode) {
  Highlight fakeHighlight = null;
  if (RunTime.get().needsRobotFake()) {
    fakeHighlight = Highlight.fakeHighlight();
  }
  logRobot(stdAutoDelay, "KeyPress: WaitForIdle: %s - Delay: %d");
  setAutoDelay(stdAutoDelay);
  if (null != fakeHighlight) {
    delay(20);
    fakeHighlight.close();
    delay(20);
  }

  // on Windows we detect the current layout in KeyboardLayout.
  // Since this layout is not compatible to AWT Robot, we have to use
  // the User32 API to simulate the key press
  if (Settings.AutoDetectKeyboardLayout && Settings.isWindows()) {
      int scanCode =  SXUser32.INSTANCE.MapVirtualKeyW(keyCode, 0);
      SXUser32.INSTANCE.keybd_event((byte)keyCode, (byte)scanCode, new WinDef.DWORD(0), new BaseTSD.ULONG_PTR(0));
  }else{
    keyPress(keyCode);
  }


  if (stdAutoDelay == 0) {
    delay(stdDelay);
  }
  logRobot("KeyPress: extended delay: %d", stdMaxElapsed);
}