SkaziChris Posted August 24, 2021 Share Posted August 24, 2021 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... expandcollapse popupFunc 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() Link to comment Share on other sites More sharing options...
Nine Posted August 24, 2021 Share Posted August 24, 2021 That seems to work well : expandcollapse popup#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 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
SkaziChris Posted August 24, 2021 Author Share Posted August 24, 2021 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 comment Share on other sites More sharing options...
Nine Posted August 24, 2021 Share Posted August 24, 2021 (edited) 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 August 24, 2021 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now