How to print to clipboard using "Send" command

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
donsonmd
Posts: 55
Joined: 19 Feb 2017, 05:57

How to print to clipboard using "Send" command

Post by donsonmd » 25 May 2023, 23:03

Is there any way to print a variable to the clipboard using "Send"?

You can obviously do as follows:

Code: Select all

Var := "a"
Clipboard := Var
But I'd like to use the command "Send" to see if it prints "a" or another language. I can check the current input language, but I need this for some reason. I thought of printing the variable to a text file and read it to determine which language it is, but it may be simpler if I can print to the clipboard. Any ideas? Thank you.

Rohwedder
Posts: 7616
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: How to print to clipboard using "Send" command

Post by Rohwedder » 26 May 2023, 07:50

Hallo,
Clipboard has no edit control. You also can't send into a normal variable.
Also, there is no such thing as a general current input language. Each window can have a different input language at the same time.
If you want to send a certain text to a window, don't send keystrokes but send in text mode
https://www.autohotkey.com/docs/v1/lib/Send.htm#Text

RussF
Posts: 1261
Joined: 05 Aug 2021, 06:36

Re: How to print to clipboard using "Send" command

Post by RussF » 26 May 2023, 09:14

See if this does what you want. It "Sends" text to an edit field in a gui that you create and then you can copy it to the clipboard if you wish. Use F10 to activate it.

Code: Select all

#Requires AutoHotkey v1.1.33+

Gui, Add, Edit, vTestinput w216 h50, %TestInput%
Gui, Add, Button,, Copy to Clipboard
Gui, Add, Button,, Hide
Gui, Add, Button, x+150, Exit
Return

ButtonCopyToClipboard:
    Gui, Submit, NoHide
    Clipboard := TestInput
Return

GuiClose:
ButtonExit:
    ExitApp

ButtonHide:
    Gui, Hide
Return

F10::
    TestInput := ""
    GuiControl,, TestInput, %TestInput%
    GuiControl, Focus, TestInput
    Gui, Show, x0 y0, TestInput
    Send, % "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
Return
Russ

Rohwedder
Posts: 7616
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: How to print to clipboard using "Send" command

Post by Rohwedder » 26 May 2023, 09:28

Shorter:

Code: Select all

F1::
ClipBoard =
SetTimer, abc, -10
Input, ClipBoard, T2
MsgBox,% ClipBoard
Return
abc:
Send,% "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
Return
But with this you can only draw conclusions about the input language of the Autohotkey script, just like with RussF's gui.

donsonmd
Posts: 55
Joined: 19 Feb 2017, 05:57

Re: How to print to clipboard using "Send" command

Post by donsonmd » 26 May 2023, 16:25

Thank you @Rohwedder and @RussF for your help. I am sorry I should have said the reason why I wanted this. I am using Microsoft Korean IME for Korean language input. It is composed of two modes:

1. "A 한" (Miscrosoft Korean IME): prints English (I don't know why this is even needed)

2. "가 한" (Miscrosoft Korean IME): prints Korean

"RAlt" key toggles between these two in Windows 11 when the cursor is ready for text input.

Windows 11 also provides "LShift & LAlt" to toggle between "ENG" and Microsoft Korean IMG ("가 한" or "A 한", whichever was the last; please see the attached screenshots)

My problem is sometimes, when I press "RAlt" to change from "A 한" to "가 한" for Korean input, the current input language is "ENG," for which "RAlt" does not work. Instead, I should have pressed "LShift & LAlt" to convert it to the Korean IME first and looked at the taskbar. If the previous Korean IME was set to "가 한" it will turn to it and I am ready to use it. But if it was "A 한" I have to press "RAlt" to covert it to "가 한."

So, I was trying to create a code that can toggle between "ENG" and "가 한" with one key. I found some code as follows (sorry for not putting the reference):

Code: Select all

#3::Toggle_ENGnKOR()

SetInputLang(Lang)
{
WinExist("A")
ControlGetFocus, CtrlInFocus
PostMessage, 0x50, 0, % Lang, %CtrlInFocus%
}

GetLocaleID()
{
LocaleID = % DllCall("GetKeyboardLayout", Int,DllCall("GetWindowThreadProcessId", int,WinActive("A"), Int,0))
Return Format("0x{:X}", LocaleID)
}

Toggle_ENGnKOR()
{
LocaleID := GetLocaleID()
If (LocaleID = "0x4120412")				; If Korean
    SetInputLang(0x04090409)				; English	0x0409
Else If (LocaleID = "0x4090409")				; If English	
    SetInputLang(0x04120412)				; Korean	0x0412
}
But the code above still changes to either "A 한" or "가 한" depending on which was the last mode, not to "가 한" always as I wish. It seems that "0x0412" refers to both "A 한" or "가 한." If something can distinguish these two, it could be used in the coding to achieve what I want. Please help me. Thank you.
Attachments
ENG.jpg
ENG.jpg (3.08 KiB) Viewed 404 times
가 한.jpg
가 한.jpg (3.02 KiB) Viewed 404 times
A 한.jpg
A 한.jpg (3.12 KiB) Viewed 404 times

RussF
Posts: 1261
Joined: 05 Aug 2021, 06:36

Re: How to print to clipboard using "Send" command

Post by RussF » 30 May 2023, 05:56

Sorry - you're using Win 11, which I don't use and you're getting into system DLL calls which is beyond my expertise. Perhaps another here can help.

Russ

Post Reply

Return to “Ask for Help (v1)”