ioa747 Posted February 7, 2023 Share Posted February 7, 2023 (edited) if i select a word in word and press the button, all good. However, when I have the native keyboard - language active, then it replaces the word with c. Was it always like this? first time I noticed it after years. And why does he send c , and not ψ ? which corresponds to the char c I tried to send it with Send("^{ASC 099}") , but nothing. I also want to notice , if I naturally press Ctrl + c then it works no matter what keyboard I have active. Is there a way to send copy (Ctrl + c ) , no matter what language I have active? #include <GUIConstantsEx.au3> Example() Func Example() GUICreate("My GUI", 320, 120) Local $idFile = GUICtrlCreateInput("Sends simulated keystrokes to the active window.", 10, 5, 300, 20) Local $idBtn = GUICtrlCreateButton("Ok", 40, 75, 60, 20) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idBtn ControlFocus ("My GUI", "", "Edit1") Send("^c") ConsoleWrite(ClipGet() & @CRLF) EndSwitch WEnd EndFunc ;==>Example Thank you very much!! Edited February 7, 2023 by ioa747 I know that I know nothing Link to comment Share on other sites More sharing options...
Solution mistersquirrle Posted February 7, 2023 Solution Share Posted February 7, 2023 (edited) You can try SendMessage or PostMessage, though not all windows will accept the commands (unless you get tricky with it, maybe). Try out this script. I works for pasting in SciTE, Windows Explorer and Notepad, but it didn't work in Visual Studio Code or Chrome, for example. It should work fine in an AutoIt GUI though. #include <SendMessage.au3> HotKeySet('[', '_Go') While 1 Sleep(10) WEnd Func _Go() Local $hHwnd = WinGetHandle('[ACTIVE]') Local $hCtrlHnd = ControlGetFocus($hHwnd) $hCtrlHnd = ControlGetHandle($hHwnd, '', $hCtrlHnd) _SendMessage($hCtrlHnd, $WM_PASTE) EndFunc Edit: plugging it into your script works: #include <SendMessage.au3> #include <GUIConstantsEx.au3> Example() Func Example() GUICreate("My GUI", 320, 120) Local $idFile = GUICtrlCreateInput("Sends simulated keystrokes to the active window.", 10, 5, 300, 20) Local $idBtn = GUICtrlCreateButton("Ok", 40, 75, 60, 20) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idBtn ControlFocus("My GUI", "", "Edit1") Local $hHwnd = WinGetHandle('[ACTIVE]') Local $hCtrlHnd = ControlGetFocus($hHwnd) $hCtrlHnd = ControlGetHandle($hHwnd, '', $hCtrlHnd) _SendMessage($hCtrlHnd, $WM_PASTE) ConsoleWrite(ClipGet() & @CRLF) EndSwitch WEnd EndFunc ;==>Example Edited February 7, 2023 by mistersquirrle ioa747 1 We ought not to misbehave, but we should look as though we could. Link to comment Share on other sites More sharing options...
ioa747 Posted February 8, 2023 Author Share Posted February 8, 2023 @mistersquirrle 👍 Thank you very much for your suggestion and response. You opened a new door for me, which was closed. _SendMessage I had to modify your script to reflect mine, I quote it for other readers #include <SendMessage.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Example() Func Example() GUICreate("My GUI", 320, 120) Local $idFile = GUICtrlCreateInput("Sends simulated keystrokes to the active window.", 10, 5, 300, 20) Local $idBtn = GUICtrlCreateButton("Ok", 40, 75, 60, 20) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idBtn ControlFocus("My GUI", "", "Edit1") Local $hHwnd = WinGetHandle('[ACTIVE]') Local $hCtrlHnd = ControlGetFocus($hHwnd) $hCtrlHnd = ControlGetHandle($hHwnd, '', $hCtrlHnd) _SendMessage($hCtrlHnd, $WM_COPY) ConsoleWrite(ClipGet() & @CRLF) EndSwitch WEnd EndFunc ;==>Example Thanks again for your time !! I know that I know nothing Link to comment Share on other sites More sharing options...
ioa747 Posted February 8, 2023 Author Share Posted February 8, 2023 however, my question remains. why the Send("^c") doesn't understand the Ctrl , while the c does, even though I have native keyboard active ?? I know that I know nothing Link to comment Share on other sites More sharing options...
jugador Posted February 8, 2023 Share Posted February 8, 2023 (edited) Send(Chr(094) & "{"& Chr(097) &"}") ;~ send: ctrl + a (select all) Send(Chr(094) & "{"& Chr(099) &"}") ;~ send: ctrl + c (copy) ConsoleWrite(ClipGet() & @CRLF) Edited February 8, 2023 by jugador Link to comment Share on other sites More sharing options...
ioa747 Posted February 8, 2023 Author Share Posted February 8, 2023 (edited) not working when I have the native keyboard - language active, then it replaces the word with c it working when I have the eng keyboard - language active Thank you Edited February 8, 2023 by ioa747 I know that I know nothing Link to comment Share on other sites More sharing options...
ioa747 Posted February 8, 2023 Author Share Posted February 8, 2023 i think the problem is with the Ctrl character because the c passes I know that I know nothing Link to comment Share on other sites More sharing options...
mistersquirrle Posted February 8, 2023 Share Posted February 8, 2023 @ioa747 It could be that AutoIt has CTRL mapped to a specific key code, and that's different in your other keyboard format. Just a thought, but I'm not sure how to go about getting and using that correct keycode in a different keyboard format/language. Unfortunately I don't believe that you can simulate the CTRL key or other modifier/system keys being 'down' with _SendMessage though. We ought not to misbehave, but we should look as though we could. Link to comment Share on other sites More sharing options...
ioa747 Posted February 8, 2023 Author Share Posted February 8, 2023 i think the problem is in Microsoft Windows Codepage 1253 (Greek) https://www.ascii-code.com/CP1252/136 I know that I know nothing Link to comment Share on other sites More sharing options...
mistersquirrle Posted February 8, 2023 Share Posted February 8, 2023 If you haven't tried it, have you tried either {CTRLDOWN} - {CTRLUP} or {LCTRL DOWN} - {LCTRL UP}, sending 'c' between them? Something like this: Send('{CTRLDOWN}') Send('c') Send('{CTRLUP}') We ought not to misbehave, but we should look as though we could. Link to comment Share on other sites More sharing options...
ioa747 Posted February 8, 2023 Author Share Posted February 8, 2023 I tried it, it doesn't work how i send Unicode U+02C6 I know that I know nothing Link to comment Share on other sites More sharing options...
ioa747 Posted February 8, 2023 Author Share Posted February 8, 2023 how i send Unicode U+02C6 To send UNICODE characters enter the character code, for example this sends a Chinese character Send("{ASC 2709}") like this? Send("{ASC 02C6}") I know that I know nothing Link to comment Share on other sites More sharing options...
jugador Posted February 8, 2023 Share Posted February 8, 2023 (edited) edit above post, check if that work Edited February 8, 2023 by jugador Link to comment Share on other sites More sharing options...
ioa747 Posted February 8, 2023 Author Share Posted February 8, 2023 2 minutes ago, jugador said: edit above post, check if that work not working when I have the native keyboard - language active, then it replaces the word with c it working when I have the eng keyboard - language active I know that I know nothing Link to comment Share on other sites More sharing options...
jugador Posted February 8, 2023 Share Posted February 8, 2023 (edited) @ioa747 ConsoleWrite('0x' & Hex(AscW('^'), 4) & @CRLF) ; ^ sign 23 hours ago, jugador said: edit above post, check if that work so did you try the modified codehttps://www.autoitscript.com/forum/topic/209642-is-there-a-way-to-send-copy-no-matter-what-language-i-have-active/?do=findComment&comment=1513043 if above still not work then try this Send(ChrW(0x005E) & "{" & ChrW(0x0061) &"}") ;~ send: ctrl + a Send(ChrW(0x005E) & "{" & ChrW(0x0063) &"}") ;~ send: ctrl + c ConsoleWrite(ClipGet() & @CRLF) or Send("{"& Chr(1) &"}") ;~ send: ctrl + a (select all) Send("{"& Chr(3) &"}") ;~ send: ctrl + c (copy) ConsoleWrite(ClipGet() & @CRLF) for the record, both method (previous code & this one) work for me and still if it not work for you then I don't know. Edited February 9, 2023 by jugador Link to comment Share on other sites More sharing options...
ioa747 Posted February 9, 2023 Author Share Posted February 9, 2023 @jugador Thank you very much for your response. with Send(ChrW(0x005E) & "{" & ChrW(0x0061) &"}") ;~ send: ctrl + a Send(ChrW(0x005E) & "{" & ChrW(0x0063) &"}") ;~ send: ctrl + c ConsoleWrite(ClipGet() & @CRLF) at the cursor i take ac with Send("{"& Chr(1) &"}") ;~ send: ctrl + a (select all) Send("{"& Chr(3) &"}") ;~ send: ctrl + c (copy) ConsoleWrite(ClipGet() & @CRLF) all text in scite replaced with but whith Send("{"& Chr(1) &"}") only, then working and select all text in scite Thanks again for your time !! I know that I know nothing Link to comment Share on other sites More sharing options...
ioa747 Posted February 10, 2023 Author Share Posted February 10, 2023 (edited) @jugador after many tests, a little luck, and a head like a pot, I finally found a solution, thanks to you for showing me the way as i described in the first post he impressed me when Send("^c") selected a word replaced with c ( And why does he send c , and not ψ ? which corresponds to the char c ) during the research process, i changed keyboard layouts, i tried the Send( ) , i changed keyboard layouts, i tried the Send( ) , at some point I noticed that Send("^c") it was not sending c any more, but ψ. for this was responsible the choice Let me use a different input method for each app window it was not checked. After I checked it, I started the tests again. In this situation, things are like this. if I highlight a word and press F5 this working. The Console write the highlighted word it works no matter what keyboard I have active. Send(ChrW(0x005E) & "{" & ChrW(0x0063) &"}") Sleep(100) ConsoleWrite(ClipGet() & @CRLF) ; Sends simulated keystrokes to the active window In this situation not working when I have the native keyboard - language active, then it replaces the word with c it working when I have the eng keyboard - language active #include <GUIConstantsEx.au3> Example() Func Example() GUICreate("My GUI", 320, 120) Local $idFile = GUICtrlCreateInput("Sends simulated keystrokes to the active window.", 10, 5, 300, 20) Local $idBtn = GUICtrlCreateButton("Ok", 40, 75, 60, 20) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idBtn ControlFocus("My GUI", "", "Edit1") ;~ Send("^c") Send(ChrW(0x005E) & "{" & ChrW(0x0063) &"}") Sleep(100) ConsoleWrite(ClipGet() & @CRLF) EndSwitch WEnd EndFunc ;==>Example In this situation working when I have the native keyboard - language active, it working when I have the eng keyboard - language active #include <GUIConstantsEx.au3> Example() Func Example() GUICreate("My GUI", 320, 120) Local $idFile = GUICtrlCreateInput("Sends simulated keystrokes to the active window.", 10, 5, 300, 20) Local $idBtn = GUICtrlCreateButton("Ok", 40, 75, 60, 20) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idBtn ControlFocus("My GUI", "", "Edit1") ;~ Send("^c") Send("{ASC 003}") ;<<<< this is working Sleep(100) ConsoleWrite(ClipGet() & @CRLF) EndSwitch WEnd EndFunc ;==>Example if this Send("{"& Chr(3) & "}") is used, regardless of which keyboard - language is active, then close the GUI How ever this showing me the way After that, i UnChecked the Let me use a different input method for each app window, to try and work and this situation conclusion: Is there a way to send copy (Ctrl + c ) , no matter what language I have active? Yes with Send("{ASC 003}") Thank you all for yours suggestions, and yours time Edited April 3, 2023 by ioa747 SOLVE-SMART 1 I know that I know nothing Link to comment Share on other sites More sharing options...
mistersquirrle Posted February 10, 2023 Share Posted February 10, 2023 That is very interesting... I'd be curious to know why these codes work. When I look at an ASCII table, it says 003 = "End of Text". I don't quite understand why/how this translates to 'Copy' when sent with Send. I did a test to find what Paste would be, and it looks like that it's: 022 = "Device control 2, block-mode flow control". Also, I'd be careful as this functionality doesn't appear to work in any/all windows, in fact for the most part it only appears to work for me in the AutoIt GUI and 'standard' or older Windows programs. Here's what I used to test and find copy/paste from your example: expandcollapse popup#include <GUIConstantsEx.au3> #include <EditConstants.au3> Local $sCopy = 'ASC 003', $sPaste = 'ASC 022' HotKeySet('[', __Copy) HotKeySet(']', __Paste) HotKeySet('{END}', __Exit) Example() Func Example() GUICreate("My GUI", 320, 120) Local $idFile = GUICtrlCreateInput("Woof", 10, 5, 300, 20, $ES_READONLY) Local $idFile2 = GUICtrlCreateInput("", 10, 35, 300, 20) Local $idBtnCopy = GUICtrlCreateButton("Copy", 40, 75, 60, 20) Local $idBtnScanCopy = GUICtrlCreateButton("ScanCopy", 110, 75, 60, 20) Local $idBtnScanPaste = GUICtrlCreateButton("ScanPaste", 180, 75, 60, 20) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idBtnCopy ControlFocus("My GUI", "", $idFile) Sleep(100) ConsoleWrite(ClipGet() & @CRLF) Case $idBtnScanCopy ControlFocus("My GUI", "", $idFile) ClipPut('Meow') For $i = 0 To 377 ConsoleWrite('Trying: ' & '{ASC ' & StringFormat('%03i', $i) & '}' & @CRLF) Send('{ASC ' & StringFormat('%03i', $i) & '}') If StringCompare(ClipGet(), 'Woof', 0) = 0 Then ConsoleWrite('Found a copy code at ' & $i & ', ' & ClipGet() & @CRLF) ExitLoop EndIf Next Case $idBtnScanPaste GUICtrlSetData($idFile2, '') ControlFocus("My GUI", "", $idFile2) ClipPut('Meow') For $i = 0 To 377 ConsoleWrite('Trying: ' & '{ASC ' & StringFormat('%03i', $i) & '}' & @CRLF) Send('{ASC ' & StringFormat('%03i', $i) & '}') If StringInStr(GUICtrlRead($idFile2), 'Meow') > 0 Then ConsoleWrite('Found a paste code at ' & $i & ', ' & ClipGet() & @CRLF) ExitLoop EndIf Next EndSwitch WEnd EndFunc ;==>Example Func __Copy() Local $sMsg = '' $sMsg = 'Copying, current: ' & StringLeft(StringRegExpReplace(ClipGet(), @CRLF & '|' & @CR & '|' & @LF, ''), 100) & ', new: ' Send('{' & $sCopy & '}') $sMsg &= ClipGet() ;~ __cLog($sMsg) ConsoleWrite($sMsg & @CRLF) EndFunc ;==>__Copy Func __Paste() ;~ __cLog('Pasting') ConsoleWrite('Pasting' & @CRLF) Send('{' & $sPaste & '}') EndFunc ;==>__Paste Func __Exit() Exit EndFunc ;==>__Exit I added hotkeys for [ and ] for copy and paste. It works fine in the AutoIt GUI, but in SciTE and Chrome it didn't work. SciTE inserted EXT and SYN, and Chrome did nothing. Notepad did however accept the copy/paste just fine. Also worked in Explorer and the older Windows Calculator (but not the newer one). If these codes work for whatever you're up to, then great, but it's not a solve all it looks like. ioa747 1 We ought not to misbehave, but we should look as though we could. Link to comment Share on other sites More sharing options...
ioa747 Posted February 11, 2023 Author Share Posted February 11, 2023 @mistersquirrle At first I liked your method.👍 After a few tests it is obvious that you are right. 👍 This also explains why I got different results on the GUI and different on the SciTE in some previous tests. 5 hours ago, mistersquirrle said: If these codes work for whatever you're up to, then great it's nothing specific, it's just for automations between applications with copy and paste. for example, a button, or an hotkey, that copies the text from a textbox, processed it , and pastes it in the same or another textbox. and surprised you see instead for this, the text in the textbox has been replaced with ψ (because you didn't notice before which keyboard is active) And this is the good scenario, because when you see the ψ you understand that it's something with the native keyboard if the text in the textbox has been replaced with c , you just restart the PC (until you understand that there is something wrong with native keyboard) for the time, the SendMessage seems safer to me. (thanks to you) PS: in the middle of this process i also found this _WinAPI_MapVirtualKey however, it needs more research for me Thank you for your attention and interest I know that I know nothing Link to comment Share on other sites More sharing options...
ioa747 Posted February 11, 2023 Author Share Posted February 11, 2023 (edited) @mistersquirrle to share my joy !! #include <WinAPISys.au3> sKey("^c") ConsoleWrite(ClipGet() & @CRLF) ;---------------------------------------------------------------------------------------- Func sKey($sKey, $iCnt = 1, $iDelay = 50) ; English (United States) 0x0409, 0x04090409 Local $Lang, $hWnd = WinGetHandle("[ACTIVE]") $Lang = _WinAPI_GetKeyboardLayout($hWnd) If $Lang <> "0x04090409" Then ; if not English then make it _WinAPI_SetKeyboardLayout($hWnd, "0x0409") EndIf For $i = 1 To $iCnt Step 1 Send($sKey) Sleep($iDelay) Next If $Lang <> "0x04090409" Then ; If was others of English set it back _WinAPI_SetKeyboardLayout($hWnd, '0x' & StringRight($Lang, 4)) EndIf EndFunc ;==>sKey ;---------------------------------------------------------------------------------------- Edited February 11, 2023 by ioa747 Remove $tmp var mistersquirrle 1 I know that I know nothing 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