Jump to content

Remote Desktop Controls Assistant


Recommended Posts

Hello!

I need to connect to my workstation using my android phone via remote connection (TeamViewer, AnyDesk, VNC, etc).

It makes my life really hard for the ctrl+c and ctrl+v operation.
I have to open the keyboard menu in the app (TV, Anydesk) and select combinations of ctrl+c,
then move to desired window, open kb menu again, and select combination of ctrl+v.

Pretty annoying.


So, I wanted to write an assistant app
that would always position itself in the middle of currently active window (and this part works),
and it would always be on top (also ok)
and it would have a few buttons performing common actions, like copy, and paste...

 

The button functionality works... - tested with MsgBox..

However, they do not copy, neither do not paste.

I tried a few combinations of Send and SendKeys function,
bot the ctrl+c/v and ctrl/shift+insert ones.

None of them work.

 

Perhaps there is a better way to do this?
Im referring to the Func copy_selection and Func paste_selection...

 

Func MoveAfterMouse()
    $MousePos = MouseGetPos()
    WinMove("Fn_keys","",$MousePos[0]+40,$MousePos[1]-140)
EndFunc

Func MoveToActiveWindow()
    $hWnd = WinActive("","")
        Sleep(1)
    if  WinGetTitle($hWnd) <> "Fn_keys"  Then
            Sleep(1)
        ;MsgBox($MB_OK,"Test",WinGetTitle($hWnd))
        Local $aPos = WinGetPos($hWnd)
        If IsArray($aPos) Then
          If IsNumber($aPos[0]) Then
            WinMove($_hWnd,"",$aPos[0]+($aPos[2]/2),$aPos[1]+($aPos[3]/2)-140)
          EndIf
        EndIf
    EndIf
EndFunc

Func copy_selection()
    Send("{CTRLDOWN}")
    Send("{INSERT}")
    Send("{CTRLUP}")
EndFunc

Func paste_selection()
    Send("{SHIFTDOWN}")
    Send("{INSERT}")
    Send("{SHIFTUP}")
EndFunc

Func _Main()

   ; Create GUI
     GUICreate("Fn_keys", 200, 60, -1, -1);, $WS_POPUP, $WS_EX_LAYERED)
     $_hWnd=WinGetHandle("Fn_keys")

    $btn_copy = GUICtrlCreateButton("Copy", 10, 10, 80, 40)
    $btn_paste = GUICtrlCreateButton("Paste", 100, 10, 80, 40)

    ;GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    ;GUICtrlSetColor(-1, 0xff00ff )
    WinSetOnTop($_hWnd, "", 1)
    GUISetState()

While 1

    MoveToActiveWindow()
   $msg = GUIGetMsg()
   Select
      Case $msg = $GUI_EVENT_CLOSE
         ExitLoop
      Case $msg = $btn_copy
        copy_selection()
      Case $msg = $btn_paste
        paste_selection()
   EndSelect
Wend

EndFunc  ;==>_Main



_Main()

 

Screenshot 2021-08-24 at 15.21.42.png

Screenshot 2021-08-24 at 15.20.53.png

Link to post
Share on other sites

That seems to work well :

#include <GUIConstants.au3>

_Main()

Func MoveToActiveWindow($hWnd)
  WinActivate($hWnd)
  WinWaitActive($hWnd)
EndFunc   ;==>MoveToActiveWindow

Func GetActiveWindow()
  Return WinGetHandle("[ACTIVE]")
EndFunc   ;==>GetActiveWindow

Func copy_selection()
  Send("^c")
  ;  Send("{CTRLDOWN}")
  ;  Send("{INSERT}")
  ;  Send("{CTRLUP}")
EndFunc   ;==>copy_selection

Func paste_selection()
  Send("^v")
  ;  Send("{SHIFTDOWN}")
  ;  Send("{INSERT}")
  ;  Send("{SHIFTUP}")
EndFunc   ;==>paste_selection

Func _Main()

  ; Create GUI
  GUICreate("Fn_keys", 200, 60, -1, -1)   ;, $WS_POPUP, $WS_EX_LAYERED)
  $_hWnd = WinGetHandle("Fn_keys")

  $btn_copy = GUICtrlCreateButton("Copy", 10, 10, 80, 40)
  $btn_paste = GUICtrlCreateButton("Paste", 100, 10, 80, 40)

  WinSetOnTop($_hWnd, "", 1)
  GUISetState()

  Local $hActive, $hCurrent

  While True
    $hActive = GetActiveWindow()
    If $hActive <> $_hWnd Then $hCurrent = $hActive
    $msg = GUIGetMsg()
    Select
      Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
      Case $msg = $btn_copy
        MoveToActiveWindow($hCurrent)
        copy_selection()
      Case $msg = $btn_paste
        MoveToActiveWindow($hCurrent)
        paste_selection()
    EndSelect
  WEnd

EndFunc   ;==>_Main

 

Link to post
Share on other sites
11 minutes ago, Nine said:

Send("^c")

Thanks, but I cannot use CTRL+C inside linux terminal,
because it does not invoke "copy". It is used as "cancel current operation" cmd.

Therefore, we (unix ppl) use ctrl+ins for copying and shift+ins for pasting things when working with terminals.

 

 

PS.
I also tried with

_SendCommand and WM_COPYDATA and WM_PASTE iMsgs,
and it works well in notepad, but does not work in terminal window...

I wonder how the windows OnScreen Keyboard sends the CTRL+INSERT  and SHIFT+INSERT kb combinations,
because it works in both windows, and autoit Send function does not...
 

Link to post
Share on other sites

Just change ^c to your Ctrl+Insert (same for paste), should work with the code I just provided.

edit : just tested and working

; to copy
Send("^{INSERT}")

; to paste
Send("+{INSERT}")

In both cases you need to activate the window you want to copy/paste by clicking on it before using your GUI buttons...

Edited by Nine
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...