StrokesPlus.net
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
thepromises  
#1 Posted : Saturday, February 20, 2021 4:34:28 AM(UTC)
thepromises

Rank: Member

Reputation:

Groups: Approved
Joined: 6/14/2019(UTC)
Posts: 14
China

Thanks: 8 times
Text prompt when Capslock is activated, how to solve it? tanks~
Rob  
#2 Posted : Saturday, February 20, 2021 4:32:28 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 post(s)
This worked for me. It creates a timer that checks every 250 milliseconds for the state of the Caps Lock key and shows a message at the bottom of the screen for 2 seconds when the state changes.

Green background when Caps Lock is ON, red when it is OFF.

Put script in:

Global Actions > Load/Unload > Load

check Enable Load Automation
Code:
sp.CreateTimer("CAPSWatch", 
               250, 
               250, 
               `if(sp.IsKeyToggled(vk.CAPITAL)) {
                   if(sp.GetStoredBool("CAPSOn") === false) {
                       sp.StoreBool("CAPSOn", true); 
                       var info = new DisplayTextInfo();
                       info.TitleFont = new Font('Segoe UI', 12, host.flags(FontStyle.Bold));
                       info.MessageFont = new Font("Segoe UI Semibold", 10);
                       info.BackColor = "37,146,52";
                       info.ForeColor = "255,255,255";
                       info.Message = "CAPS Lock is ON";
                       info.Duration = 2000;
                       info.Location = "bottom"; 
                       info.Padding = 10;
                       sp.DisplayText(info);
                   }
               } else {
                   if(sp.GetStoredBool("CAPSOn") === true) {
                       sp.StoreBool("CAPSOn", false); 
                       var info = new DisplayTextInfo();
                       info.TitleFont = new Font('Segoe UI', 12, host.flags(FontStyle.Bold));
                       info.MessageFont = new Font("Segoe UI Semibold", 10);
                       info.BackColor = "200,56,70";
                       info.ForeColor = "255,255,255";
                       info.Message = "CAPS Lock is OFF";
                       info.Duration = 2000;
                       info.Location = "bottom"; 
                       info.Padding = 10;
                       sp.DisplayText(info);
                   }
               }`
);
lyscop  
#3 Posted : Monday, February 22, 2021 12:11:48 PM(UTC)
soooulp

Rank: Advanced Member

Reputation:

Groups: Moderators, Approved
Joined: 4/23/2020(UTC)
Posts: 161
China

Thanks: 46 times
Was thanked: 23 time(s) in 17 post(s)
Originally Posted by: Rob Go to Quoted Post
This worked for me. It creates a timer that checks every 250 milliseconds for the state of the Caps Lock key and shows a message at the bottom of the screen for 2 seconds when the state changes.

Green background when Caps Lock is ON, red when it is OFF.

Put script in:

Global Actions > Load/Unload > Load

check Enable Load Automation



Hi, Rob, How to keep the green message show if the caps lock is on, and it will miss when the caps lock is off.

Then, whether it can show a message when the Microsoft input change to the Chinese input method.
Rob  
#4 Posted : Monday, February 22, 2021 1:55:58 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 post(s)
First: You must download and install this plug-in:

https://forum.strokesplus.net/posts/t1009-Keyboard-Layout

Download first, then in S+ go to Plug-Ins > Search Locations and click Add Plug-In, then select the KeyboardLayout.dll file you downloaded.



Next: You will need to determine which keyboard layout code you are using for Chinese:

From this page: https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/windows-language-pack-default-values

Chinese (Simplified) - US Keyboard: 0x804
Chinese (Traditional) - US Keyboard: 0x404
Chinese (Traditional, Hong Kong S.A.R.): 0xc04
Chinese (Traditional Macao S.A.R.) US Keyboard: 0x1404
Chinese (Simplified, Singapore) - US keyboard: 0x1004



Then replace the previous script with this new script.

This continually shows the green message while Caps Lock is on and/or Chinese keyboard layout is active, dismiss when Caps Lock is off and keyboard layout is not Chinese.

I have Chinese (Simplified) - US Keyboard (0x804) as the code in the script below, change if not correct!
Code:
sp.CreateTimer("CAPSLangWatch", 
               250, 
               250, 
               `var info = new DisplayTextInfo();
               info.TitleFont = new Font('Segoe UI', 12, host.flags(FontStyle.Bold));
               info.MessageFont = new Font("Segoe UI Semibold", 10);
               info.BackColor = "37,146,52";
               info.ForeColor = "255,255,255";
               info.Duration = 1000;
               info.Location = "bottom"; 
               info.Padding = 10;
               info.Message = "";
               if(sp.IsKeyToggled(vk.CAPITAL)) {
                   info.Message = "CAPS Lock is ON";
               }
               try {
                   if(new Keyboard().GetCurrentKeyboardLayout() === 0x804) {  //<-- change keyboard value here if needed
                       if(info.Message.length > 0) info.Message += " - ";
                       info.Message += "Chinese Keyboard ACTIVE";
                   }
               } catch {}           
               if(info.Message.length > 0) { 
                   if(sp.GetStoredBool("CAPSLangShown")) {
                       sp.DisplayTextUpdate(info);
                   } else { 
                       sp.DisplayText(info);
                       sp.StoreBool("CAPSLangShown", true);
                   }
               } else {
                   sp.DisplayTextClose();
                   sp.StoreBool("CAPSLangShown", false);
               }
               `
);
thanks 1 user thanked Rob for this useful post.
soooulp on 2/22/2021(UTC)
lyscop  
#5 Posted : Monday, February 22, 2021 2:38:02 PM(UTC)
soooulp

Rank: Advanced Member

Reputation:

Groups: Moderators, Approved
Joined: 4/23/2020(UTC)
Posts: 161
China

Thanks: 46 times
Was thanked: 23 time(s) in 17 post(s)
Originally Posted by: Rob Go to Quoted Post
First: You must download and install this plug-in:

https://forum.strokesplus.net/posts/t1009-Keyboard-Layout

Download first, then in S+ go to Plug-Ins > Search Locations and click Add Plug-In, then select the KeyboardLayout.dll file you downloaded.



Next: You will need to determine which keyboard layout code you are using for Chinese:

From this page: https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/windows-language-pack-default-values

Chinese (Simplified) - US Keyboard: 0x804
Chinese (Traditional) - US Keyboard: 0x404
Chinese (Traditional, Hong Kong S.A.R.): 0xc04
Chinese (Traditional Macao S.A.R.) US Keyboard: 0x1404
Chinese (Simplified, Singapore) - US keyboard: 0x1004



Then replace the previous script with this new script.

This continually shows the green message while Caps Lock is on and/or Chinese keyboard layout is active, dismiss when Caps Lock is off and keyboard layout is not Chinese.

I have Chinese (Simplified) - US Keyboard (0x804) as the code in the script below, change if not correct!



Thank you, Rob, it works well, which shows the message.

thepromises  
#6 Posted : Tuesday, February 23, 2021 6:39:04 AM(UTC)
thepromises

Rank: Member

Reputation:

Groups: Approved
Joined: 6/14/2019(UTC)
Posts: 14
China

Thanks: 8 times
Originally Posted by: lyscop Go to Quoted Post
Originally Posted by: Rob Go to Quoted Post
This worked for me. It creates a timer that checks every 250 milliseconds for the state of the Caps Lock key and shows a message at the bottom of the screen for 2 seconds when the state changes.

Green background when Caps Lock is ON, red when it is OFF.

Put script in:

Global Actions > Load/Unload > Load

check Enable Load Automation



Hi, Rob, How to keep the green message show if the caps lock is on, and it will miss when the caps lock is off.

Then, whether it can show a message when the Microsoft input change to the Chinese input method.


Code:

sp.CreateTimer("CAPSWatch", 
               250, 
               250, 
               `if(sp.IsKeyToggled(vk.CAPITAL)) {
                   if(sp.GetStoredBool("CAPSOn") === false) {
                       sp.StoreBool("CAPSOn", true); 
                       var info = new DisplayTextInfo();
                       info.TitleFont = new Font('Segoe UI', 12, host.flags(FontStyle.Bold));
                       info.MessageFont = new Font("Segoe UI Semibold", 18);
                       info.BackColor = "0,0,0";
                       info.ForeColor = "255,255,255";
                       info.Message = "CapsLock is ON";
                       info.Duration = 86400;
                       info.Location = "bottom"; 
                       info.Padding = 15;
                       sp.DisplayText(info);
                   }
               } else {
                   if(sp.GetStoredBool("CAPSOn") === true) {
                       sp.StoreBool("CAPSOn", false); 
                       var info = new DisplayTextInfo();
                       info.TitleFont = new Font('Segoe UI', 12, host.flags(FontStyle.Bold));
                       info.MessageFont = new Font("Segoe UI Semibold", 18);
                       info.BackColor = "0,0,0";
                       info.ForeColor = "255,255,255";
                       info.Message = "CapsLock is OFF";
                       info.Duration = 500;
                       info.Location = "bottom"; 
                       info.Padding = 15;
                       sp.DisplayText(info);
                   }
               }`
);



lyscop  
#7 Posted : Tuesday, February 23, 2021 6:49:40 AM(UTC)
soooulp

Rank: Advanced Member

Reputation:

Groups: Moderators, Approved
Joined: 4/23/2020(UTC)
Posts: 161
China

Thanks: 46 times
Was thanked: 23 time(s) in 17 post(s)
Originally Posted by: thepromises Go to Quoted Post
Originally Posted by: lyscop Go to Quoted Post
Originally Posted by: Rob Go to Quoted Post
This worked for me. It creates a timer that checks every 250 milliseconds for the state of the Caps Lock key and shows a message at the bottom of the screen for 2 seconds when the state changes.

Green background when Caps Lock is ON, red when it is OFF.

Put script in:

Global Actions > Load/Unload > Load

check Enable Load Automation



Hi, Rob, How to keep the green message show if the caps lock is on, and it will miss when the caps lock is off.

Then, whether it can show a message when the Microsoft input change to the Chinese input method.





哈哈设置时间我想到了,试下Rob的方法,很好用

避免了弹其他消息覆盖掉这个消息框,所以得消息都叠加在这个里面显示

lyscop  
#8 Posted : Tuesday, February 23, 2021 7:36:28 AM(UTC)
soooulp

Rank: Advanced Member

Reputation:

Groups: Moderators, Approved
Joined: 4/23/2020(UTC)
Posts: 161
China

Thanks: 46 times
Was thanked: 23 time(s) in 17 post(s)
Originally Posted by: Rob Go to Quoted Post
First: You must download and install this plug-in:

https://forum.strokesplus.net/posts/t1009-Keyboard-Layout

Download first, then in S+ go to Plug-Ins > Search Locations and click Add Plug-In, then select the KeyboardLayout.dll file you downloaded.


Hi, Rob, I am here to trouble you again.

GetCurrentKeyboardLayout() is a good function to recognize which Keyboard is. I find there is another function ImmGetConversionStatus() in Windows.

https://docs.microsoft.com/en-us/windows/win32/api/imm/nf-imm-immgetconversionstatus

Code:

BOOL ImmGetConversionStatus(
  HIMC    ,
  LPDWORD lpfdwConversion,
  LPDWORD lpfdwSentence
);


It seems that can recognize which mode I choose, as the Chinese(simple) - US Keyboard, Chinese(simple) or US is a different model.

I set this code to get the input model as a gesture and it shows a bug, so can you help me to use this function to get the 'curImode'.

Code:

[DllImport("imm32.dll")]
        public static extern IntPtr ImmGetContext(IntPtr hWnd);

[DllImport("imm32.dll")]
        public static extern bool ImmGetConversionStatus(IntPtr hIMC,
            ref int conversion, ref int sentence);

IntPtr prt = ImmGetContext(this.Handle);
int curIMode = 0;
int curISentence = 0;
ImmGetConversionStatus(prt,ref curIMode,ref curISentence);
sp.ShowBalloonTip('Title',curIMode,'Info',5000);


I do not know whether the following count to divide the model can be suited for S+net and it seems to work well by C# as the link.

https://www.cnblogs.com/cellphoneyeah/p/6834786.html

标准模式(全拼模式,比如智能ABC的标准模式)

输入法状态 mode值
中文输入-半角-中文符号 1025
中文输入-全角-中文符号 1033
中文输入-半角-英文符号 1
中文输入-全角-英文符号 9
英文输入-半角-中文符号 1024
英文输入-全角-中文符号 1032
英文输入-半角-英文符号 0
英文输入-全角-英文符号 8


Rob  
#9 Posted : Tuesday, February 23, 2021 4:23:32 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 post(s)
You can create platform invoke declarations in S+, but you have to use custom methods for this as pure C# code in JavaScript will not work.

Global Actions > Load/Unload > Load
Code:
// Only do this if the IMM32 module has not been created
if(!NativeModules.IMM32)
{
    // Create types used for method declarations
    var IntPtrT = host.typeOf(clr.System.IntPtr);
    var BooleanT = host.typeOf(clr.System.Boolean);
    // Create the ref int type for curIMode and curISentence
	var int_refT = host.typeOf(clr.System.Int32).MakeByRefType();
	
	//------------------------------------------------------------------------------------------------
    // Define the IMM32 type and create the pinvoke methods
    //------------------------------------------------------------------------------------------------

    var imm32TB = sp.NativeModule().DefineType("IMM32", "Class,Public,SequentialLayout,Serializable");
	
	imm32TB.DefinePInvokeMethod("ImmGetContext",
								 "imm32.dll",
								 [IntPtrT], 
								 IntPtrT, 
								 "PreserveSig");

	imm32TB.DefinePInvokeMethod("ImmGetConversionStatus",
								 "imm32.dll",
								 [IntPtrT,int_refT,int_refT], 
								 BooleanT, 
								 "PreserveSig");

    //Create the type (no further changes to type can be made)
    imm32TB.Create();
}

Code to execute API calls:
I put this in a gesture action, just to test - but it can be easily used anywhere else
Code:
var prt = NativeModules.IMM32.ImmGetContext(sp.ForegroundWindow().HWnd);
var curIMode = host.newVar(clr.System.Int32);
var curISentence = host.newVar(clr.System.Int32);
var ret = NativeModules.IMM32.ImmGetConversionStatus(prt, curIMode.ref, curISentence.ref);

sp.MessageBox(`ret: ${ret}
curIMode: ${curIMode.value}
curISentence: ${curISentence.value}`, "Return Values");
thanks 1 user thanked Rob for this useful post.
soooulp on 2/23/2021(UTC)
soooulp  
#10 Posted : Tuesday, February 23, 2021 5:15:51 PM(UTC)
soooulp

Rank: Advanced Member

Reputation:

Groups: Moderators, Approved
Joined: 4/23/2020(UTC)
Posts: 161
China

Thanks: 46 times
Was thanked: 23 time(s) in 17 post(s)
Originally Posted by: Rob Go to Quoted Post
You can create platform invoke declarations in S+, but you have to use custom methods for this as pure C# code in JavaScript will not work.

Global Actions > Load/Unload > Load



Thank you so so so much, Rob.

I do not know whether ImmGetConversionStatus() function loses efficacy, it always shows '0' no matter I change to Chinese(Simple) or US model in any program.

UserPostedImage

Rob  
#11 Posted : Tuesday, February 23, 2021 5:21:34 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 post(s)
Hmm, I am not familiar with actually using that API, so I am not sure.

Can you paste the actual script making the call?
Rob  
#12 Posted : Tuesday, February 23, 2021 5:28:00 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 post(s)
It looks like there are a lot of API calls involving IME functions, apparently ImmReleaseContext needs to be called each time ImmGetContext is called, to release the memory:

See Remarks section
https://docs.microsoft.com/en-us/windows/win32/api/imm/nf-imm-immgetcontext

https://docs.microsoft.com/en-us/windows/win32/api/imm/nf-imm-immreleasecontext



There's also ImmGetOpenStatus, which might have something to do with it:

https://docs.microsoft.com/en-us/windows/win32/api/imm/nf-imm-immgetopenstatus

Also, it's not clear if the HWnd should be for the overall window, or the handle to the input control itself..?

I've never used any of the Imm API calls, so I am not at all familiar with this stuff :-(
soooulp  
#13 Posted : Tuesday, February 23, 2021 5:31:15 PM(UTC)
soooulp

Rank: Advanced Member

Reputation:

Groups: Moderators, Approved
Joined: 4/23/2020(UTC)
Posts: 161
China

Thanks: 46 times
Was thanked: 23 time(s) in 17 post(s)
Originally Posted by: Rob Go to Quoted Post
Hmm, I am not familiar with actually using that API, so I am not sure.

Can you paste the actual script making the call?


Originally I want to recognize the model and keep a message shows on the screen. Now I just test the count.

As I find the count if I change to the Chinese(Simple) model it will shows '1025' what I do not concern about it.

The second one is US model which shows '0' will be OK.

输入法状态 mode值
中文输入-半角-中文符号 1025
中文输入-全角-中文符号 1033
中文输入-半角-英文符号 1
中文输入-全角-英文符号 9
英文输入-半角-中文符号 1024
英文输入-全角-中文符号 1032
英文输入-半角-英文符号 0
英文输入-全角-英文符号 8

UserPostedImage

UserPostedImage



soooulp  
#14 Posted : Tuesday, February 23, 2021 5:33:54 PM(UTC)
soooulp

Rank: Advanced Member

Reputation:

Groups: Moderators, Approved
Joined: 4/23/2020(UTC)
Posts: 161
China

Thanks: 46 times
Was thanked: 23 time(s) in 17 post(s)
Originally Posted by: Rob Go to Quoted Post
It looks like there are a lot of API calls involving IME functions, apparently ImmReleaseContext needs to be called each time ImmGetContext is called, to release the memory:

See Remarks section
https://docs.microsoft.com/en-us/windows/win32/api/imm/nf-imm-immgetcontext

https://docs.microsoft.com/en-us/windows/win32/api/imm/nf-imm-immreleasecontext



There's also ImmGetOpenStatus, which might have something to do with it:

https://docs.microsoft.com/en-us/windows/win32/api/imm/nf-imm-immgetopenstatus

Also, it's not clear if the HWnd should be for the overall window, or the handle to the input control itself..?

I've never used any of the Imm API calls, so I am not at all familiar with this stuff :-(


Aha, Thank you for your efforts again, let it go.


soooulp  
#15 Posted : Tuesday, March 2, 2021 3:42:11 PM(UTC)
soooulp

Rank: Advanced Member

Reputation:

Groups: Moderators, Approved
Joined: 4/23/2020(UTC)
Posts: 161
China

Thanks: 46 times
Was thanked: 23 time(s) in 17 post(s)
Originally Posted by: Rob Go to Quoted Post
First: You must download and install this plug-in:

https://forum.strokesplus.net/posts/t1009-Keyboard-Layout

Download first, then in S+ go to Plug-Ins > Search Locations and click Add Plug-In, then select the KeyboardLayout.dll file you downloaded.



Next: You will need to determine which keyboard layout code you are using for Chinese:

From this page: https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/windows-language-pack-default-values

Chinese (Simplified) - US Keyboard: 0x804
Chinese (Traditional) - US Keyboard: 0x404
Chinese (Traditional, Hong Kong S.A.R.): 0xc04
Chinese (Traditional Macao S.A.R.) US Keyboard: 0x1404
Chinese (Simplified, Singapore) - US keyboard: 0x1004



Then replace the previous script with this new script.

This continually shows the green message while Caps Lock is on and/or Chinese keyboard layout is active, dismiss when Caps Lock is off and keyboard layout is not Chinese.

I have Chinese (Simplified) - US Keyboard (0x804) as the code in the script below, change if not correct!


Can it show separate two or more message boxes in different back colors on the screen?

Like one for CAPS Lock, and one for CurrentKeyboard.
Rob  
#16 Posted : Wednesday, March 3, 2021 4:14:37 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 post(s)
Unfortunately, the built-in method only supports one display text window being shown at any time.

You can look at liuxilu's example of creating your own form here and change the logic as needed (second comment in thread, in spoiler tag):

https://forum.strokesplus.net/posts/t7202-Enhanced-sp-ShowImage
soooulp  
#17 Posted : Wednesday, March 3, 2021 4:18:25 PM(UTC)
soooulp

Rank: Advanced Member

Reputation:

Groups: Moderators, Approved
Joined: 4/23/2020(UTC)
Posts: 161
China

Thanks: 46 times
Was thanked: 23 time(s) in 17 post(s)
Originally Posted by: Rob Go to Quoted Post
Unfortunately, the built-in method only supports one display text window being shown at any time.

You can look at liuxilu's example of creating your own form here and change the logic as needed (second comment in thread, in spoiler tag):

https://forum.strokesplus.net/posts/t7202-Enhanced-sp-ShowImage


Use the image to show the flag is a good way, let me have a try.


soooulp  
#18 Posted : Friday, March 5, 2021 3:12:59 PM(UTC)
soooulp

Rank: Advanced Member

Reputation:

Groups: Moderators, Approved
Joined: 4/23/2020(UTC)
Posts: 161
China

Thanks: 46 times
Was thanked: 23 time(s) in 17 post(s)
Originally Posted by: Rob Go to Quoted Post
Unfortunately, the built-in method only supports one display text window being shown at any time.

You can look at liuxilu's example of creating your own form here and change the logic as needed (second comment in thread, in spoiler tag):

https://forum.strokesplus.net/posts/t7202-Enhanced-sp-ShowImage


I am failed to set the Form Controls as identification of Caps lock in Global Actions > Load/Unload, because of its unfocus the original input window.

And I still want to change the color of the showing text box.

The last struggle of this show message:

Whether if can DisplayTextUpdate or the Message box not change the back color when adding a message on the existing message box, such as the following photos, the second one is what I want, and I designed it.

I find DisplayTextUpdate can change the message, the location, or else.

This does not work:



First one:
UserPostedImage

Second one:
UserPostedImage




Rob  
#19 Posted : Friday, March 5, 2021 5:24:54 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 post(s)
Updated sp.DisplayTextUpdate to also check to see if back/fore colors have changed and update them.

Added in version 0.4.1.7.
thanks 1 user thanked Rob for this useful post.
soooulp on 3/5/2021(UTC)
soooulp  
#20 Posted : Friday, March 5, 2021 5:29:36 PM(UTC)
soooulp

Rank: Advanced Member

Reputation:

Groups: Moderators, Approved
Joined: 4/23/2020(UTC)
Posts: 161
China

Thanks: 46 times
Was thanked: 23 time(s) in 17 post(s)
Originally Posted by: Rob Go to Quoted Post
Updated sp.DisplayTextUpdate to also check to see if back/fore colors have changed and update them.

Added in version 0.4.1.7.


I don't know how to express my thanks for your help.
Rob  
#21 Posted : Friday, March 5, 2021 6:09:02 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 post(s)
You're very welcome!

It seems it was just something I failed to account for.
soooulp  
#22 Posted : Saturday, August 21, 2021 4:10:15 PM(UTC)
soooulp

Rank: Advanced Member

Reputation:

Groups: Moderators, Approved
Joined: 4/23/2020(UTC)
Posts: 161
China

Thanks: 46 times
Was thanked: 23 time(s) in 17 post(s)
Originally Posted by: Rob Go to Quoted Post
You're very welcome!

It seems it was just something I failed to account for.


It is still the problem of the state of the input, as it is that there is the state in the Chinese input method, like Cn and En, and it can be switch by Win+Space.

I used a default Chinese input method and a US keyboard installed from the US language, so the state could be recognized by Keyboard-Layout if I execute Win+Space, then display some words on the screen, but now it can't work well for some reason.

Last time, I found the Windows API ImmGetConversionStatus() that didn't work in the S+.

I find that the state of the input can be recognized by call the DLL of windows, like in Autohotkey. So I still like the text display style in S+.

The following is the code written by a Japanese to get the state of the input.

If it is convenient for you to help me consider whether it can be written as a plugin-in to use in the S+.

https://qiita.com/shufo/items/84447520973dfc27733d

It seems that IME_GET() = 1 is Cn, and 0 is En, and it also can set the default input method to the particulate programs like CMD uses En, Word uses Cn, though there is a setting in windows to set the different program to separate input method.

Code:

IME_GET(WinTitle="")
;-----------------------------------------------------------
; IMEの状態の取得
;    対象: AHK v1.0.34以降
;   WinTitle : 対象Window (省略時:アクティブウィンドウ)
;   戻り値  1:ON 0:OFF
;-----------------------------------------------------------
{
    ifEqual WinTitle,,  SetEnv,WinTitle,A
    WinGet,hWnd,ID,%WinTitle%
    DefaultIMEWnd := DllCall("imm32\ImmGetDefaultIMEWnd", Uint,hWnd, Uint)

    ;Message : WM_IME_CONTROL  wParam:IMC_GETOPENSTATUS
    DetectSave := A_DetectHiddenWindows
    DetectHiddenWindows,ON
    SendMessage 0x283, 0x005,0,,ahk_id %DefaultIMEWnd%
    DetectHiddenWindows,%DetectSave%
    Return ErrorLevel
}

IME_SET(setSts, WinTitle="")
;-----------------------------------------------------------
; IMEの状態をセット
;    対象: AHK v1.0.34以降
;   SetSts  : 1:ON 0:OFF
;   WinTitle: 対象Window (省略時:アクティブウィンドウ)
;   戻り値  1:ON 0:OFF
;-----------------------------------------------------------
{
    ifEqual WinTitle,,  SetEnv,WinTitle,A
    WinGet,hWnd,ID,%WinTitle%
    DefaultIMEWnd := DllCall("imm32\ImmGetDefaultIMEWnd", Uint,hWnd, Uint)

    ;Message : WM_IME_CONTROL  wParam:IMC_SETOPENSTATUS
    DetectSave := A_DetectHiddenWindows
    DetectHiddenWindows,ON
    SendMessage 0x283, 0x006,setSts,,ahk_id %DefaultIMEWnd%
    DetectHiddenWindows,%DetectSave%
    Return ErrorLevel
}



Rob  
#23 Posted : Monday, August 23, 2021 3:45:50 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 post(s)
I don't have Chinese or Japanese installed, so I can't fully test this - but let me know if it works for you.

Global Actions > Load/Unload > Load script
Code:
//Define IME constants
const WM_IME_CONTROL = 0x283;
const IMC_GETOPENSTATUS = 0x005;

//If the Imm32 module has not already been defined
if(!NativeModules.Imm32)
{
    var IntPtrT = host.typeOf(System.IntPtr);

    //Define imm32 type
    var imm32TB = sp.NativeModule().DefineType("Imm32", "Class,Public,SequentialLayout,Serializable");
	
	//Define the platform invoke call
	//From: https://docs.microsoft.com/en-us/windows/win32/api/imm/nf-imm-immgetdefaultimewnd
	imm32TB.DefinePInvokeMethod("ImmGetDefaultIMEWnd",
								 "imm32.dll",
								 [IntPtrT], 
								 IntPtrT, 
								 "PreserveSig");	

	//Create the type (finalize, now made an official C# class)					 
    imm32TB.Create();								 

    //Note: Changes cannot be made to a class once created. If you need to change or add
    //      anything, you must restart S+ to update the class.
}


Action / Hotkey / Etc script
Code:
//Get the default IME window for the current foreground window
//Change this as needed, if you are working with an action, use action.Window.Hwnd
var imeWnd = NativeModules.Imm32.ImmGetDefaultIMEWnd(sp.ForegroundWindow().HWnd);

//Send the message and store return value
var ret = sp.WindowFromHandle(imeWnd).SendMessageObj(WM_IME_CONTROL, IMC_GETOPENSTATUS, 0x0);

//Print the return value to Console > User tab (right-click tray, select console)
StrokesPlus.Console.Log(ret);
thanks 1 user thanked Rob for this useful post.
soooulp on 8/23/2021(UTC)
soooulp  
#24 Posted : Monday, August 23, 2021 4:55:40 PM(UTC)
soooulp

Rank: Advanced Member

Reputation:

Groups: Moderators, Approved
Joined: 4/23/2020(UTC)
Posts: 161
China

Thanks: 46 times
Was thanked: 23 time(s) in 17 post(s)
Originally Posted by: Rob Go to Quoted Post
I don't have Chinese or Japanese installed, so I can't fully test this - but let me know if it works for you.

Global Actions > Load/Unload > Load script


Action / Hotkey / Etc script


It is amazing, and it works so perfectly so far with the Shift to switch between En and Cn.

The tooltip '中' is Cn, and 'En' is En from the AHK script.

Thank you so much.

I use sp.MessageBox(ret, 'ret'); shows '1' or '0', but when I use sp.ShowBalloonTip('m',`${ret}`,'Info',1000); to output the value, it show Object, or if(ret === 1) { doesn't work.
Also in the console, it shows time+ num, how to use the ret value in the IF…ELSE….

UserPostedImage

Rob  
#25 Posted : Monday, August 23, 2021 5:09:26 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 post(s)
The sp.SendMessageObj method returns a System.IntPtr struct.

You can convert it to a 32-bit number via the ToInt32() method:

Code:
if(ret.ToInt32() === 1) {
    sp.MessageBox('ret === 1', '1');    
}
thanks 1 user thanked Rob for this useful post.
soooulp on 8/23/2021(UTC)
soooulp  
#26 Posted : Monday, August 23, 2021 5:23:09 PM(UTC)
soooulp

Rank: Advanced Member

Reputation:

Groups: Moderators, Approved
Joined: 4/23/2020(UTC)
Posts: 161
China

Thanks: 46 times
Was thanked: 23 time(s) in 17 post(s)
Originally Posted by: Rob Go to Quoted Post
The sp.SendMessageObj method returns a System.IntPtr struct.

You can convert it to a 32-bit number via the ToInt32() method:

Code:
if(ret.ToInt32() === 1) {
    sp.MessageBox('ret === 1', '1');    
}



Aha, the reality input state is back again.

By the way, I find the Fade Steps option in the setting, is there a fade steps variable in the DisplayTextInfo

UserPostedImage
Rob  
#27 Posted : Monday, August 23, 2021 6:10:09 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 post(s)
I've added FadeSteps in 0.5.4.8:

Code:
info.FadeSteps = 18;
thanks 1 user thanked Rob for this useful post.
soooulp on 8/24/2021(UTC)
2014218866  
#28 Posted : Wednesday, December 1, 2021 2:58:27 PM(UTC)
2014218866

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 5/6/2019(UTC)
Posts: 111
China

Thanks: 19 times
Was thanked: 1 time(s) in 1 post(s)

Dear friends, can it be realized that no matter whether the input method is Chinese or English, it can be converted into English by using the shfit key with gestures, because S+ cannot perform certain gestures in the Chinese state. thank you very much。
Originally Posted by: soooulp Go to Quoted Post
Originally Posted by: Rob Go to Quoted Post
You can create platform invoke declarations in S+, but you have to use custom methods for this as pure C# code in JavaScript will not work.

Global Actions > Load/Unload > Load



Thank you so so so much, Rob.

I do not know whether ImmGetConversionStatus() function loses efficacy, it always shows '0' no matter I change to Chinese(Simple) or US model in any program.

UserPostedImage



2014218866  
#29 Posted : Wednesday, December 1, 2021 3:04:16 PM(UTC)
2014218866

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 5/6/2019(UTC)
Posts: 111
China

Thanks: 19 times
Was thanked: 1 time(s) in 1 post(s)
To put it simply: S+ judges the state of the default Chinese input method. If it is Chinese, it will switch to the English state by shift key. If it is in the English state, the English input state will be maintained.
soooulp  
#30 Posted : Friday, December 3, 2021 1:18:45 PM(UTC)
soooulp

Rank: Advanced Member

Reputation:

Groups: Moderators, Approved
Joined: 4/23/2020(UTC)
Posts: 161
China

Thanks: 46 times
Was thanked: 23 time(s) in 17 post(s)
Originally Posted by: 2014218866 Go to Quoted Post
To put it simply: S+ judges the state of the default Chinese input method. If it is Chinese, it will switch to the English state by shift key. If it is in the English state, the English input state will be maintained.


Aha, I find it is easy to achieve it based on Rob's code.

I try this and it can set the input method into Ch or En, no matter what the present input method is.


0x1 is Ch input method:

Code:
const WM_IME_CONTROL_a = 0x283;
const IMC_GETOPENSTATUS_a = 0x006;
sp.WindowFromHandle(imeWnd).SendMessageObj(WM_IME_CONTROL_a, IMC_GETOPENSTATUS_a, 0x1);



0x0 is En input method:

Code:
const WM_IME_CONTROL_b = 0x283;
const IMC_GETOPENSTATUS_b = 0x006;
sp.WindowFromHandle(imeWnd).SendMessageObj(WM_IME_CONTROL_b, IMC_GETOPENSTATUS_b, 0x0);





thanks 1 user thanked soooulp for this useful post.
2014218866 on 12/4/2021(UTC)
2014218866  
#31 Posted : Saturday, December 4, 2021 7:55:39 AM(UTC)
2014218866

Rank: Advanced Member

Reputation:

Groups: Approved
Joined: 5/6/2019(UTC)
Posts: 111
China

Thanks: 19 times
Was thanked: 1 time(s) in 1 post(s)
THANKS A LOT
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.