Need to know how to insert "["

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Archimede
Posts: 503
Joined: 25 Nov 2021, 09:49
Location: Switzerland / Italy

Need to know how to insert "["

26 Mar 2024, 12:04

Hallo.
I need to know what keys I need to press to insert "[" char: some keyboards needs to press Shift + the right key, some othet keyboards need to press AltGr + the right key (it depend from the Keyboard language).
I know what is the necessary key name, but I need to know what is the modifier key ( Shift or AltGr ) necessary.
The real problem is much complex, but this is the core of the problem.
Thanks to anyone can help to solve this problem.
User avatar
JoeWinograd
Posts: 2200
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: Need to know how to insert "["

26 Mar 2024, 12:50

Hi @Archimede,
Instead of trying to figure out what keys to press, you could simply send it via the Chr function. For example:

Code: Select all

LeftBracket:=Chr(91)
Send %LeftBracket%
MsgBox % LeftBracket
Regards, Joe
Archimede
Posts: 503
Joined: 25 Nov 2021, 09:49
Location: Switzerland / Italy

Re: Need to know how to insert "["

26 Mar 2024, 13:03

When I need to detect what modifier key to use I must no send anyhing.
User avatar
JoeWinograd
Posts: 2200
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: Need to know how to insert "["

26 Mar 2024, 13:18

Archimede wrote:When I need to detect what modifier key to use I must no send anyhing.
Then I don't understand your end goal. Your initial post says:
I need to know what keys I need to press to insert "["
In order to insert "[", you can Send % Chr(91). If that's not what you're trying to do, please explain further. Regards, Joe
Archimede
Posts: 503
Joined: 25 Nov 2021, 09:49
Location: Switzerland / Italy

Re: Need to know how to insert "["

26 Mar 2024, 13:37

I told the real problem is much complex, this is only the core problem.
I need the program saves a file where is wrote how to produce the "[" char by the current keyboard; the program knows what is the key, but no knows what is the modifier ( shift or AltGr ).
The same problem exist for many other chars, but when solved this it is possible to apply the same solution to all other chars.
Thank you very much.
User avatar
JoeWinograd
Posts: 2200
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: Need to know how to insert "["

26 Mar 2024, 14:24

I don't know how to determine which modifier keys are needed for which characters. So, if you're trying to produce documentation on that, I can't help...hopefully, someone else in the group will jump in. If you're actually trying to send/insert all such characters via a script, I would address them one at a time, e.g., Chr(91) (left bracket), Chr(95) (underscore), Chr(125) (right brace), etc., until the script has handled all such characters.
Rohwedder
Posts: 7655
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Need to know how to insert "["

27 Mar 2024, 03:29

Hallo,
try:

Code: Select all

F1::
ControlGetFocus Focused, A
ControlGet CtrlID, Hwnd,, % Focused, A
ThreadID := DllCall("GetWindowThreadProcessId", "Ptr", CtrlID, "Ptr", 0)
InputLocaleID := DllCall("GetKeyboardLayout", "UInt", ThreadID, "Ptr")
LanguageID := Format("{:08X}", InputLocaleID & 0xFFFF)
Run, http://kbdlayout.info/%LanguageID%
Return
It shows the keyboard scheme valid for the active window.
I have only tested my installed keyboards. The url calculation may not fit everywhere!
The overview page is http://kbdlayout.info/
Archimede
Posts: 503
Joined: 25 Nov 2021, 09:49
Location: Switzerland / Italy

Re: Need to know how to insert "["

27 Mar 2024, 04:46

Thank you very much.
The link is very interesting.
But the problem remain: how is possible to detect, from the program, what modifier keys ( Shift or AltGr ) are necessary to press with a char key to generate a specific character (like "[" for example)?
Rohwedder
Posts: 7655
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Need to know how to insert "["

27 Mar 2024, 04:56

This is probably defined somewhere in the active keyboard layout. I have no idea whether Autohotkey can read this. But with the above variable InputLocaleID the script knows which keyboard layout is active and can look it up in a list (Array).
Archimede
Posts: 503
Joined: 25 Nov 2021, 09:49
Location: Switzerland / Italy

Re: Need to know how to insert "["

27 Mar 2024, 05:20

Yes, it is interesting, but I think it is no possible to define an array with ALL chars and all keys of a keyboard for EVERY language...
Rohwedder
Posts: 7655
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Need to know how to insert "["

27 Mar 2024, 06:09

This script memorizes (Array Keys) which character is written by which keys.

Code: Select all

Gui +AlwaysOnTop +HwndGUI
Gui Add, Edit, vChar
Gui Show
SendMode, Input
SetWinDelay, 0
SetBatchLines, -1
Keys := {}
Loop, 0xFF
	IF (""<Key := GetKeyName(Format("VK{:X}", A_Index)))
	{
		ControlSend, Edit1, ^a{Bs}{%Key%}, ahk_id %GUI%
		Gui, Submit, NoHide
		Keys[Asc(Char)] := Key
		ControlSend, Edit1, ^a{Bs}+{%Key%}, ahk_id %GUI%
		Gui, Submit, NoHide
		Keys[Asc(Char)] := "+" Key
		ControlSend, Edit1, ^a{Bs}{LCtrl Down}{RAlt Down}{%Key%}{LCtrl Up}{RAlt Up}, ahk_id %GUI%
		Gui, Submit, NoHide
		Keys[Asc(Char)] := "AltGr+" Key
	}
Gui, Destroy
MsgBox,% "Character ""a"" is written by " Keys[Asc("a")]
MsgBox,% "Character ""A"" is written by " Keys[Asc("A")]
MsgBox,% "Character ""["" is written by " Keys[Asc("[")]
Archimede
Posts: 503
Joined: 25 Nov 2021, 09:49
Location: Switzerland / Italy

Re: Need to know how to insert "["

27 Mar 2024, 10:06

It is very interesting, thanks.
It is very difficult to automatize it to automatically detect all keys and keys combination.
I found a mode to detect all scan code exists and all keys exists: then I have an array with all scan codes and all key names: starting from that, can you found a mode to detect all keys combination and all characters generates by that key combination?
Rohwedder
Posts: 7655
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Need to know how to insert "["

27 Mar 2024, 10:37

It is easy to recognize all pressed key combinations.
All currently pressed keys and buttons are displayed. A mouse wheel rotation saves it to the clipboard:

Code: Select all

#InstallKeybdHook
#InstallMouseHook
SetTimer, KeyCombination, 50,% ClipBoard := ""
KeyCombination:
IF A_TimeIdlePhysical > 100
    Return
KeyCombination := KeyCombination()
ToolTip,% KeyCombination?"you are pressing`n" KeyCombination
:"ClipBoard:`n" ClipBoard
Return
*WheelUp::
*WheelDown::ClipBoard := KeyCombination 
KeyCombination(ExcludeKeys:="")
{ ;All pressed keys and buttons will be listed
    ExcludeKeys .= "{Shift}{Control}{Alt}{WheelUp}{WheelDown}"
    Loop, 0xFF
    {
        IF !GetKeyState(Key:=Format("VK{:02X}",0x100-A_Index),"P")
            Continue
        If !InStr(ExcludeKeys,Key:="{" GetKeyName(Key) "}")
            KeyCombination .= RegexReplace(Key,"Numpad(\D+)","$1")
    }
    Return, KeyCombination
}
But all characters generates by that key combination?!
No! In German we say to something like this:
"von hinten durch die Brust ins Auge schießen" = "shoot from behind through the chest into the eye"
The above memorizing script does not even find all of them on my German keyboard!
There are also a few dead keys.
Archimede
Posts: 503
Joined: 25 Nov 2021, 09:49
Location: Switzerland / Italy

Re: Need to know how to insert "["

27 Mar 2024, 11:55

I think it would be a solution a Function (or similar) like Send, but that assign the value to a variable instead send that value to a window.
Rohwedder
Posts: 7655
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Need to know how to insert "["

27 Mar 2024, 12:56

I agree with that! But unfortunately there is no VariableSend
Instead of sending to an Edit Control you could send to an InputHook(), but I was afraid that Windows might do strange things.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Araphen and 176 guests