Jump to content

Is there a way to send copy , no matter what language I have active?


ioa747
 Share

Go to solution Solved by mistersquirrle,

Recommended Posts

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 by ioa747

I know that I know nothing

Link to comment
Share on other sites

  • Solution

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 by mistersquirrle

We ought not to misbehave, but we should look as though we could.

Link to comment
Share on other sites

@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

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 by ioa747

I know that I know nothing

Link to comment
Share on other sites

@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

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

@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 code
https://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 by jugador
Link to comment
Share on other sites

@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 image.png.b0169d007f6944795b74c582347bc96e.png

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

@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 me230209-162322-935_ApplicationFrameHost_mGb4p.png.b4bcc39d97f7272d0e320832644bfb40.png

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 by ioa747

I know that I know nothing

Link to comment
Share on other sites

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:

#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.

We ought not to misbehave, but we should look as though we could.

Link to comment
Share on other sites

@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

@mistersquirrle  :guitar::frantics:

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 by ioa747
Remove $tmp var

I know that I know nothing

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...