Skip to content

Commit

Permalink
Moved stability sleeps to the right place. Also stopped freeing
Browse files Browse the repository at this point in the history
the LibFreeRDP instance which was causing segmentation faults.
  • Loading branch information
iiordanov committed Jan 9, 2017
1 parent 19c1999 commit 3e1dd16
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 47 deletions.
26 changes: 20 additions & 6 deletions eclipse_projects/bVNC/src/com/iiordanov/bVNC/RdpCommunicator.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,14 @@ public String getEncoding() {
@Override
public void writePointerEvent(int x, int y, int metaState, int pointerMask) {
this.metaState = metaState;
if ((pointerMask & RemoteRdpPointer.PTRFLAGS_DOWN) != 0)
if ((pointerMask & RemoteRdpPointer.PTRFLAGS_DOWN) != 0) {
sendModifierKeys(true);
}
try { Thread.sleep(5); } catch (InterruptedException e) {}
LibFreeRDP.sendCursorEvent(session.getInstance(), x, y, pointerMask);
if ((pointerMask & RemoteRdpPointer.PTRFLAGS_DOWN) == 0)
if ((pointerMask & RemoteRdpPointer.PTRFLAGS_DOWN) == 0) {
sendModifierKeys(false);
}
}

@Override
Expand Down Expand Up @@ -111,7 +114,7 @@ public DisconnectThread (long i) {
}
public void run () {
LibFreeRDP.disconnect(instance);
LibFreeRDP.freeInstance(instance);
//LibFreeRDP.freeInstance(instance);
}
}

Expand All @@ -121,40 +124,47 @@ public void close() {
long instance = session.getInstance();
DisconnectThread d = new DisconnectThread(instance);
d.start();
//session = null;
}

private void sendModifierKeys (boolean down) {
if ((metaState & RemoteKeyboard.CTRL_MASK) != 0) {
//android.util.Log.e("RdpCommunicator", "Sending LCTRL " + down);
try { Thread.sleep(5); } catch (InterruptedException e) {}
LibFreeRDP.sendKeyEvent(session.getInstance(), VK_LCONTROL, down);
}
if ((metaState & RemoteKeyboard.RCTRL_MASK) != 0) {
//android.util.Log.e("RdpCommunicator", "Sending RCTRL " + down);
try { Thread.sleep(5); } catch (InterruptedException e) {}
LibFreeRDP.sendKeyEvent(session.getInstance(), VK_RCONTROL, down);
}
if ((metaState & RemoteKeyboard.ALT_MASK) != 0) {
//android.util.Log.e("RdpCommunicator", "Sending LALT " + down);
try { Thread.sleep(5); } catch (InterruptedException e) {}
LibFreeRDP.sendKeyEvent(session.getInstance(), VK_LMENU, down);
}
if ((metaState & RemoteKeyboard.RALT_MASK) != 0) {
//android.util.Log.e("RdpCommunicator", "Sending RALT " + down);
try { Thread.sleep(5); } catch (InterruptedException e) {}
LibFreeRDP.sendKeyEvent(session.getInstance(), VK_RMENU, down);
}
if ((metaState & RemoteKeyboard.SUPER_MASK) != 0) {
//android.util.Log.e("RdpCommunicator", "Sending LSUPER " + down);
try { Thread.sleep(5); } catch (InterruptedException e) {}
LibFreeRDP.sendKeyEvent(session.getInstance(), VK_LWIN | VK_EXT_KEY, down);
}
if ((metaState & RemoteKeyboard.RSUPER_MASK) != 0) {
//android.util.Log.e("RdpCommunicator", "Sending RSUPER " + down);
try { Thread.sleep(5); } catch (InterruptedException e) {}
LibFreeRDP.sendKeyEvent(session.getInstance(), VK_RWIN | VK_EXT_KEY, down);
}
if ((metaState & RemoteKeyboard.SHIFT_MASK) != 0) {
//android.util.Log.e("RdpCommunicator", "Sending LSHIFT " + down);
try { Thread.sleep(5); } catch (InterruptedException e) {}
LibFreeRDP.sendKeyEvent(session.getInstance(), VK_LSHIFT, down);
}
if ((metaState & RemoteKeyboard.RSHIFT_MASK) != 0) {
//android.util.Log.e("RdpCommunicator", "Sending RSHIFT " + down);
try { Thread.sleep(5); } catch (InterruptedException e) {}
LibFreeRDP.sendKeyEvent(session.getInstance(), VK_RSHIFT, down);
}
}
Expand All @@ -163,18 +173,22 @@ private void sendModifierKeys (boolean down) {
// KeyboardMapper.KeyProcessingListener implementation
@Override
public void processVirtualKey(int virtualKeyCode, boolean down) {
if (down)
if (down) {
sendModifierKeys(true);
}
//android.util.Log.e("RdpCommunicator", "Sending VK key: " + virtualKeyCode + ". Is it down: " + down);
try { Thread.sleep(5); } catch (InterruptedException e) {}
LibFreeRDP.sendKeyEvent(session.getInstance(), virtualKeyCode, down);
if (!down)
if (!down) {
sendModifierKeys(false);
}
}

@Override
public void processUnicodeKey(int unicodeKey) {
android.util.Log.e(TAG, "Unicode character: " + unicodeKey);
sendModifierKeys(true);
try { Thread.sleep(5); } catch (InterruptedException e) {}
LibFreeRDP.sendUnicodeKeyEvent(session.getInstance(), unicodeKey);
sendModifierKeys(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,12 +470,6 @@ public boolean processAndroidKeyEvent(KeyEvent event) {
case KeyEvent.ACTION_DOWN:
{
boolean modifierActive = isModifierPressed();

boolean shiftPressed = event.isShiftPressed();
boolean altPressed = event.isAltPressed();
boolean ctrlPressed = event.isCtrlPressed();
boolean winPressed = event.isMetaPressed();
boolean isAnyModifierPressed = (shiftPressed|altPressed|ctrlPressed|winPressed);

// if a modifier is pressed we will send a VK event (if possible) so that key combinations will be
// recognized correctly. Otherwise we will send the unicode key. At the end we will reset all modifiers
Expand All @@ -484,57 +478,25 @@ public boolean processAndroidKeyEvent(KeyEvent event) {
//android.util.Log.e("KeyMapper", "VK KeyCode is: " + vkcode);
if((vkcode & KEY_FLAG_UNICODE) != 0) {
//android.util.Log.i("KeyMapper", "vkcode & KEY_FLAG_UNICODE " + vkcode);
try { Thread.sleep(5); } catch (InterruptedException e) {}
listener.processUnicodeKey(vkcode & (~KEY_FLAG_UNICODE));
} else if ((vkcode & KEY_FLAG_SHIFT) != 0){
//android.util.Log.i("KeyMapper", "vkcode & KEY_FLAG_SHIFT " + vkcode);
vkcode = vkcode & ~KEY_FLAG_SHIFT;
listener.processVirtualKey(VK_LSHIFT, true);
try { Thread.sleep(5); } catch (InterruptedException e) {}
listener.processVirtualKey(vkcode, true);
try { Thread.sleep(5); } catch (InterruptedException e) {}
listener.processVirtualKey(vkcode, false);
try { Thread.sleep(5); } catch (InterruptedException e) {}
listener.processVirtualKey(VK_LSHIFT, false);
// if we got a valid vkcode send it - except for letters/numbers if a modifier is active
} else if (vkcode > 0 && ! isAnyModifierPressed) {
//android.util.Log.i("KeyMapper", "vkcode > 0 && ! isAnyModifierPressed " + vkcode);
} else if (vkcode > 0) {
//android.util.Log.i("KeyMapper", "vkcode > 0" + vkcode);
listener.processVirtualKey(vkcode, true);
try { Thread.sleep(5); } catch (InterruptedException e) {}
listener.processVirtualKey(vkcode, false);
}
else if(vkcode > 0 && isAnyModifierPressed)
{
//android.util.Log.i("KeyMapper", "vkcode > 0 && isAnyModifierPressed " + vkcode);

if (shiftPressed)
listener.processVirtualKey(VK_LSHIFT, true);
if (ctrlPressed)
listener.processVirtualKey(VK_CONTROL, true);
if (altPressed)
listener.processVirtualKey(VK_MENU, true);
if (winPressed)
listener.processVirtualKey(VK_LWIN, true);
try { Thread.sleep(5); } catch (InterruptedException e) {}
listener.processVirtualKey(vkcode, true);
try { Thread.sleep(5); } catch (InterruptedException e) {}
listener.processVirtualKey(vkcode, false);
try { Thread.sleep(5); } catch (InterruptedException e) {}
if (shiftPressed)
listener.processVirtualKey(VK_LSHIFT, false);
if (ctrlPressed)
listener.processVirtualKey(VK_CONTROL, false);
if (altPressed)
listener.processVirtualKey(VK_MENU, false);
if (winPressed)
listener.processVirtualKey(VK_LWIN, false);
}
else if(event.getUnicodeChar() != 0) {
//android.util.Log.i("KeyMapper", "event.getUnicodeChar() != 0 " + vkcode);
//KeyEvent copy = new KeyEvent(event.getDownTime(), event.getEventTime(),
// event.getAction(), event.getKeyCode(), event.getRepeatCount(),
// 0, event.getDeviceId(), event.getScanCode());
try { Thread.sleep(5); } catch (InterruptedException e) {}
listener.processUnicodeKey(event.getUnicodeChar());
} else {
//android.util.Log.i("KeyMapper", "else " + vkcode);
Expand All @@ -551,7 +513,6 @@ else if(event.getUnicodeChar() != 0) {
{
String str = event.getCharacters();
for(int i = 0; i < str.length(); i++) {
try { Thread.sleep(5); } catch (InterruptedException e) {}
listener.processUnicodeKey(str.charAt(i));
}
return true;
Expand Down

0 comments on commit 3e1dd16

Please sign in to comment.