1

I need my Arduino (Leonardo) to open cmd, but if keyboard input language isn’t English it prints another language letters.

——— code ———

Keyboard.begin();
Keyboard.press(KEY_LEFT_GUI);
Keyboard.press('r');
delay(1000);
Keyboard.releaseAll();
Keyboard.write("cmd");
Keyboard.press(KEY_RETURN);
Keyboard.releaseAll();
delay(1000);

——— ——— ———

So my question is: can I somehow detect language, and if it’s not there add it?

My idea was to set languagelist via powershell, and it would be perfect for my program, but I don’t know how I can write English text from Arduino on pc with another language :(

Also my Arduino has sd card, maybe it helps.

——— code ———

powershell $OldList = Get-WinUserLanguageList

powershell Set-WinUserLanguageList -LanguageList en-US -Force

-something

powershell Set-WinUserLanguageList -LanguageList $OldList -Force

——— ——— ———

Sorry if it is 0iq question, I’m very new to Arduino, it will be great to hear your ideas!

6
  • 1
    your question is not about Arduino
    – jsotola
    Sep 21 at 6:01
  • @jsotola, oh sorry, but about what is it then? Can i rephrase my question like: Is there a way to print english text via arduino on system with another input language? thank you for your reply! Sep 21 at 6:57
  • 1
    As any other USB keyboard, your Arduino cannot change the host's input language. There is no way that your keyboard can directly change the input language. Sep 21 at 7:09
  • Absolutely no way? Like copy from file from sd or check it somehow? Thank you anyway @thebusybee! Sep 21 at 7:18
  • Maybe there is a way to check printed text and if it is not english alt+shift? Sep 21 at 7:25

2 Answers 2

2

Your Arduino will be virtually typing on a keyboard like this:

unlabeled keyboard
© Aon fi – CC-BY 3.0

See the labels on the keys? There are none. Your Windows OS has its own idea of what each key means, but the Arduino has no way of knowing that. Instead, you have to tell it explicitly what keyboard layout to use, e.g.:

Keyboard.begin(KeyboardLayout_fr_FR);

If you don't, the Keyboard library will assume KeyboardLayout_en_US.

There is no way the computer can tell the keyboard what layout it expects.

6
  • That's sad, thank you for your reply, now i'm undarstand it Sep 21 at 7:20
  • Sorry, Maybe there is a way to check printed text and if it is not english alt+shift? @EdgarBonet Sep 21 at 7:33
  • @Mapagmataas: Yes, you can check by looking at the screen. But a keyboard cannot do that, and neither can an Arduino posing as a keyboard. Sep 21 at 7:35
  • Sorry, i am newby with arduino) Thank you! Sep 21 at 7:36
  • @Mapagmataas it has nothing to do with Arduino ... the problem is with computers and keyboards
    – jsotola
    Sep 21 at 14:19
1

i finaly found a solution for my problem. I wrote an algorithm, that automaticly change system input language if there are only two languages and one of them is English. This code is writen on Duckduino shortcuts, but it is not a problem to convert it back.

DELAY 1000

GUI r
DELAY 1000
STRING powershell
ENTER
DELAY 1000
STRING "ok"
ENTER
DELAY 1000
STRING Set-WinUserLanguageList -LanguageList en-US, ru -Force
ENTER
DELAY 1000
STRING exit
ENTER
DELAY 1000

ALT SHIFT
DELAY 1000
GUI r
DELAY 1000
STRING powershell
ENTER
DELAY 1000
STRING "ok"
ENTER
DELAY 1000
STRING Set-WinUserLanguageList -LanguageList ru, en-US -Force
ENTER
DELAY 1000
ALT SHIFT
DELAY 1000
STRING exit
ENTER
DELAY 1000

GUI r
DELAY 1000
STRING powershell
ENTER
DELAY 1000
STRING "ENGLISH"
ENTER
DELAY 1000

You can use for ru another language, for "ok" i want to add Get-WinUserLanguageList | ConvertTo-Json | Out-File C:\WinUserLanguageList.json to save user's list.

Than language is different than english this code makes errors, and than language is right it changes language list, thats how it works!

Update:

DELAY 1000

GUI r
DELAY 1000
STRING powershell
ENTER
DELAY 1000
STRING Get-WinUserLanguageList | ConvertTo-Json | Out-File C:\WinUserLanguageList.json
ENTER
DELAY 1000
STRING Set-WinUserLanguageList -LanguageList en-US, ru -Force
ENTER
DELAY 1000
STRING exit
ENTER
DELAY 1000

ALT SHIFT
DELAY 1000
GUI r
DELAY 1000
STRING powershell
ENTER
DELAY 1000
STRING Get-WinUserLanguageList | ConvertTo-Json | Out-File C:\WinUserLanguageList.json
ENTER
DELAY 1000
STRING Set-WinUserLanguageList -LanguageList ru, en-US -Force
ENTER
DELAY 1000
ALT SHIFT
DELAY 1000
STRING exit
ENTER
DELAY 1000

GUI r
DELAY 1000
STRING powershell
ENTER
DELAY 1000
STRING "CODE IN ENGLISH"
ENTER
DELAY 1000
STRING exit
ENTER
DELAY 1000

GUI r
DELAY 1000
STRING powershell
ENTER
DELAY 1000
STRING Get-WinUserLanguageList
ENTER
DELAY 1000
STRING $importedFile = Get-Content C:\WinUserLanguageList.json | ConvertFrom-Json
ENTER
DELAY 1000
STRING $langCollection = New-Object System.Collections.Generic.List[Microsoft.InternationalSettings.Commands.WinUserLanguage]
ENTER
DELAY 1000
STRING foreach ($item in $importedFile) {
ENTER
DELAY 1000
STRING $lang = [Microsoft.InternationalSettings.Commands.WinUserLanguage]::new($item.LanguageTag)
ENTER
DELAY 1000
STRING $lang.InputMethodTips.Clear()
ENTER
DELAY 1000
STRING foreach ($inputMethod in $item.InputMethodTips) {
ENTER
DELAY 1000
STRING $lang.InputMethodTips.Add($inputMethod) }
ENTER
DELAY 1000
STRING $lang.Handwriting = $item.Handwriting
ENTER
DELAY 1000
STRING $lang.Spellchecking = $item.Spellchecking
ENTER
DELAY 1000
STRING $langCollection += $lang }
ENTER
DELAY 1000
STRING Set-WinUserLanguageList $langCollection -Force
ENTER
DELAY 1000
STRING Remove-Item C:\WinUserLanguageList.json
ENTER
DELAY 1000
STRING exit
ENTER
DELAY 1000

GUI r
DELAY 1000
STRING https://ma.kak.si
ENTER

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.