The Chinese characters output by the following code are not accurate. Can you identify the problem?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
kfj000
Posts: 26
Joined: 24 Sep 2021, 10:06

The Chinese characters output by the following code are not accurate. Can you identify the problem?

Post by kfj000 » 23 Mar 2023, 01:13

The Chinese characters output by the following code are not accurate. Can you identify the problem?

Code: Select all

$F12::
	temp := StrSplit("张三,李四,王五", [",","\n"] ) 
	for index,element in temp 
	{
		Sleep,1000 
		SendText("@") 
		Sleep,500 
		temp[index] := StrReplace(temp[index], "@") 
		SendText(temp[index]) 
		Sleep,500 
		send,{ENTER} 
	}
	msgbox,0,微信点名,结束 
return

SendText(str) 
{
	ControlGetFocus,classnn,A 
	p := &str 
	while,*p 
	{
		if (*p>128 && *(p+1)>=64) 
		{
			ch := *p << 8 | *(p+1) 
			PostMessage,0x286,%ch%,0x1,%classnn%,A 
			p += 2 
		}
		Else 
		{
			ch := *p 
			Send,{ASC %ch%} 
			p++ 
		}
	}
}

User avatar
lmstearn
Posts: 688
Joined: 11 Aug 2016, 02:32
Contact:

Re: The Chinese characters output by the following code are not accurate. Can you identify the problem?

Post by lmstearn » 24 Mar 2023, 01:33

Hi @kfj000, had a look at it, ran out of time for a complete solution, this should help a bit:

Code: Select all

$F12::

	temp := "张三,李四,王五"
	temp1 := []

	Loop, Parse, temp , CSV, `n
	{
		Sleep,1000 
		SendText("@") 
		Sleep,500
		temp1[A_Index] := StrReplace(A_Loopfield, "张三", "this_is_replace_text") 

		SendText(temp1[A_Index]) 
		Sleep,500 
		send,{ENTER} 
	}
	msgbox,0,微信点名,结束 
return
Esc::
ExitApp

SendText(str) 
{
	ControlGetFocus,classnn,A 
	p := &str 
	while,*p 
	{
		if (*p>128 && *(p+1)>=64) 
		{
			ch := *p << 8 | *(p+1) 
			PostMessage,0x286,%ch%,0x1,%classnn%,A 
			p += 2 
		}
		Else 
		{
			ch := *p 
			Send,{ASC %ch%} 
			p++ 
		}
	}
}
:arrow: itros "ylbbub eht tuO kaerB" a ni kcuts m'I pleH

off
Posts: 176
Joined: 18 Nov 2022, 21:54

Re: The Chinese characters output by the following code are not accurate. Can you identify the problem?

Post by off » 24 Mar 2023, 06:42

Im not sure if i understand the problem, what kind of output you want?
Output like this?

Code: Select all

@张三
@李四
@王五
Idk what is yours and Imstearn code for, and how it works,
Both yours and Imstrean's code return me

Code: Select all

@t
@Ng�
@譳鑎
I try use this:

Code: Select all

$F12::
temp := StrSplit("张三,李四,王五", [",","\n"] )
for index,element in temp 
{
;MsgBox, %index% %element%
Send, `@
Sleep, 200
Send, %element%
send, {ENTER} 
}
msgbox,0,微信点名,结束
return
and return

Code: Select all

@张三
@李四
@王五

Is this what you need or else? please let me know
My Creations
IMG2HotString - Send image file easily with your hotstring!
CtrlSend - A small solution for sending keys to window in background that doesn't accept ControlSend's key
ControlProcess

User avatar
kfj000
Posts: 26
Joined: 24 Sep 2021, 10:06

Re: The Chinese characters output by the following code are not accurate. Can you identify the problem?

Post by kfj000 » 26 Mar 2023, 03:50

The correct output is:
@张三
@李四
@王五

But the output of this code is like this, I don't know why.
@t
@Ng�
@譳鑎

@lmstearn The result after your code runs is still the same:


User avatar
kfj000
Posts: 26
Joined: 24 Sep 2021, 10:06

Re: The Chinese characters output by the following code are not accurate. Can you identify the problem?

Post by kfj000 » 26 Mar 2023, 08:59

@off
If someone's name is called "有人@你的啊",after running your code, you will see the following result in WeChat.
@有人@有人@你的啊

garry
Posts: 3740
Joined: 22 Dec 2013, 12:50

Re: The Chinese characters output by the following code are not accurate. Can you identify the problem?

Post by garry » 26 Mar 2023, 15:41

script from @off works for me
for test , example saves file as UTF-8 with BOM and open it , then use F12 to send

Code: Select all

F1:=a_desktop . "\test.txt"
fileappend,,%f1%,utf-8
run,notepad "%f1%"
return
;-----------
$F12::
clipboard=
temp := StrSplit("张三,有人@你的啊,李四,王五", [",","\n"] )
 ;- I don't know when '@' must be sent ...
for index,element in temp
  {
  if element contains `@
    clipboard:=element
  else
    clipboard:="@" . element
  send,^v`n
  clipboard=
  }
msgbox,0,微信点名,结束
return
;------------
esc::exitapp
;============
;- or again

Code: Select all

;--
#Requires AutoHotkey v1.1
#Warn
#Singleinstance,force
SetKeyDelay, 80, 10
;-
F1:=a_desktop . "\test.txt"
e=
(
The correct output is:
@张三
@李四
@王五
;-----------------

)
fileappend,%e%,%f1%,utf-8
try
run,notepad "%f1%"
#If WinActive("ahk_exe notepad.exe")
return
;-----------
$F9::
send,^{end}
sleep,400
clipboard=
var:="张三,李四,王五"
Loop,parse,var,`, 
  {
  x:= A_LoopField
  if x=
    continue
  clipboard:="@" . x
  send,^v`n
  clipboard=
  }
#If  
msgbox,0,微信点名,结束
return
;------------
esc::exitapp
;============
Last edited by garry on 27 Mar 2023, 07:06, edited 1 time in total.

off
Posts: 176
Joined: 18 Nov 2022, 21:54

Re: The Chinese characters output by the following code are not accurate. Can you identify the problem?

Post by off » 26 Mar 2023, 19:50

kfj000 wrote: The correct output is:
@张三
@李四
@王五
My code return this for me, if you need more delay, perhaps

Code: Select all

$F12::
temp := StrSplit("张三,李四,王五", [",","\n"] )
for index,element in temp 
{
;MsgBox, %index% %element%
Send, `@
Sleep, 200 ; adjust your Delay here,
Send, %element%
Sleep, 200 ; and here.
send, {ENTER} 
}
msgbox,0,微信点名,结束
return
My Creations
IMG2HotString - Send image file easily with your hotstring!
CtrlSend - A small solution for sending keys to window in background that doesn't accept ControlSend's key
ControlProcess

User avatar
kfj000
Posts: 26
Joined: 24 Sep 2021, 10:06

Re: The Chinese characters output by the following code are not accurate. Can you identify the problem?

Post by kfj000 » 27 Mar 2023, 00:36

@garry
The result that appears in the WeChat chat box after your code runs is:
@张三
有人@你的啊
@有人@你的啊 @王五

@off
The result that appears in the WeChat chat box after your code runs is:
@张三
@有人@有人@你的啊 @李四
@王五

The code I provided appears in the WeChat chat box after running, and the result is:
@ _N
@g멎`葶OJU
@Ng�
@譳鑎
The results are accurate, but the Chinese characters are garbled,I don't know why.The code encoding is selected: UTF-8 with BOM.

User avatar
lmstearn
Posts: 688
Joined: 11 Aug 2016, 02:32
Contact:

Re: The Chinese characters output by the following code are not accurate. Can you identify the problem?

Post by lmstearn » 27 Mar 2023, 04:21

Sorry, errors with the above post- the first element displays correctly on Send, the others don't.

Code: Select all

$F12::

	temp := "张三,李四,王五"
	temp1 := []

	Loop, Parse, temp, CSV, `n
	{
		Sleep,1000 
		SendText("@") 
		Sleep,500
		temp1[A_Index] := StrReplace(A_Loopfield, "@") 
		msgbox % temp1[A_Index]
		SendText(temp1[A_Index]) 
		Sleep,500 
		send,{ENTER} 
	}
	msgbox,0,微信点名,结束 
return
Esc::
ExitApp

SendText(str) 
{
	ControlGetFocus,classnn,A 
	p := &str 
	while,*p 
	{
		if (*p>128 && *(p+1)>=64) 
		{
			ch := *p << 8 | *(p+1) 
			PostMessage,0x286,%ch%,0x1,%classnn%,A 
			p += 2 
		}
		Else 
		{
			ch := *p 
			Send,{ASC %ch%} 
			p++ 
		}
	}
}
Is it anything to do with the characters themselves - when using SendText(temp1[1]) instead, the same desired result appears, so no issue with the receptor in that case. Maybe a better result using Ord(), see here. Could also be a problem with how WM_SETTEXT handles it, Chinese characters are 3 bytes.
Edit: Wait a minute, you have _N for the first character and I'm getting _○N - the is a placeholder for a missing Chinese character. Is that a thing at all?
:arrow: itros "ylbbub eht tuO kaerB" a ni kcuts m'I pleH

Post Reply

Return to “Ask for Help (v1)”