Detect alphabet / keyboard layout from stringHow to recover data from a bad SD card?Combine input from...

Was Robin Hood's point of view ethically sound?

Expected value until a success?

What is the use of FullForm in Mathematica?

How is the Team Scooby Doo funded?

How can I protect myself in case of a human attack like the murders of the hikers Jespersen and Ueland in Morocco?

Can I say "I will encrypt something" if I hash something?

Are scroll bars dead in 2019?

Awesomism and its awesome gods

What is this next to the kitchen bar sink?

Is there a star over my head?

How to create a list of dictionaries from a dictionary with lists of different lengths

Transitive Relations: Special case

Are the definite and indefinite integrals actually two different things? Where is the flaw in my understanding?

Why was "leaping into the river" a valid trial outcome to prove one's innocence?

Has any object launched from Earth gone into the Sun?

Why didn't Thor use the All powerful spear instead of Stormbreaker?

Georgian capital letter “Ⴒ” (“tar”) in pdfLaTeX

Can I use ratchet straps to lift a dolly into a truck bed?

Are there any space probes or landers which regained communication after being lost?

Is English tonal for some words, like "permit"?

Are there any instances of members of different Hogwarts houses coupling up and marrying each other?

Determining if file in projected or geographic coordinates using ArcGIS Desktop?

Why would "an mule" be used instead of "a mule"?

Where does the expression "triple-A" comes from?



Detect alphabet / keyboard layout from string


How to recover data from a bad SD card?Combine input from multiple files/pipes without clobbering lines or blocking?How would one detect if external command exists in a script?How can I use sed to replace a multi-line string?How to change the current directory graphically using the keyboard only?Where does the “export” command come from?Determine monthly internet transfer to detect right FUPHow do I show the numeric character sequence of a string?Select added lines from fileGet line number from byte offset






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







0















Is there some existing tool that can detect keyboard layout needed from string?



As in not language, but layout.



The case



I use xdotool to paste text into an application that does not accept paste.



That is: I use xdotool type … on the text in clipboard.



When I paste for example Russian xdotool detects which layout to use and changes this automatically (from the looks of it).



The detection method is very slow though. The longer the text, the worse.



A string of 130 letters for example takes over 30 seconds when layout needs to be changed.





setxkbmap



I have found that changing the keyboard before using xdotool speeds things up to the normal. For this reason I added a simple layout detection method. It is very crude and is set up only to detect the languages I paste in (beside English).



orig_lang=$(setxkbmap -query | awk '/^layout:/{printf $2}')
lang=$(language "$text")

if [ ! -z "$lang" ] && [[ "$lang" != "$cur_lang" ]]; then
printf "Changing kbmap to %sn" "$lang" >&2
setxkbmap $lang
fi
xdotool type --delay 52 "$text"
if [ ! -z "$lang" ]; then
setxkbmap $orig_lang
fi


``



Where the language function for now is:



language()
{
local -i found=1
local lan
local letters
local letter
local -i len
local -i i
# Note: AaOoPp etc. in ru is not the same as in English
local -A dd=(
[ru]="АаБбВвГгДдЕеЁёЖжЗзИиЙйКкЛл†МмНнОоПпРрСсТтУуФфХхЦцЧчШшЩщЪъЫыЬьЭэЮюЯя"
[no]="ÆØÅæøå"
[de]="ßüÜäÄÖö"
)

[ -z "$1" ] && return 1

for lan in ${!dd[@]}; do
letters=${dd[$lan]}
len=${#letters}
for (( i = 0; i < len; ++i)); do
letter="${letters:$i:1}"
if [ -z "${1##*$letter*}" ]; then
printf $lan
found=0
break 2
fi
done
done
return $found
}




Alternative?



Is there a better existing alternative for this?



Optionally another tool then xdotool which uses another way of detecting or sending keystrokes?



I have tried guess_language and the like.



Issue is that they are language and not alphabet oriented. As such I get possible false results and single words or short sentences return unknown.










share|improve this question



























  • Can't thing of a much better alternative, even though I would use your strings in regular expressions (for instance, russian would be something like .*[АаБбВвГгДдЕеЁёЖжЗзИиЙйКкЛл†МмНнОоПпРрСсТтУуФфХхЦцЧчШшЩщЪъЫыЬьЭэЮюЯя].*.

    – xenoid
    3 hours ago


















0















Is there some existing tool that can detect keyboard layout needed from string?



As in not language, but layout.



The case



I use xdotool to paste text into an application that does not accept paste.



That is: I use xdotool type … on the text in clipboard.



When I paste for example Russian xdotool detects which layout to use and changes this automatically (from the looks of it).



The detection method is very slow though. The longer the text, the worse.



A string of 130 letters for example takes over 30 seconds when layout needs to be changed.





setxkbmap



I have found that changing the keyboard before using xdotool speeds things up to the normal. For this reason I added a simple layout detection method. It is very crude and is set up only to detect the languages I paste in (beside English).



orig_lang=$(setxkbmap -query | awk '/^layout:/{printf $2}')
lang=$(language "$text")

if [ ! -z "$lang" ] && [[ "$lang" != "$cur_lang" ]]; then
printf "Changing kbmap to %sn" "$lang" >&2
setxkbmap $lang
fi
xdotool type --delay 52 "$text"
if [ ! -z "$lang" ]; then
setxkbmap $orig_lang
fi


``



Where the language function for now is:



language()
{
local -i found=1
local lan
local letters
local letter
local -i len
local -i i
# Note: AaOoPp etc. in ru is not the same as in English
local -A dd=(
[ru]="АаБбВвГгДдЕеЁёЖжЗзИиЙйКкЛл†МмНнОоПпРрСсТтУуФфХхЦцЧчШшЩщЪъЫыЬьЭэЮюЯя"
[no]="ÆØÅæøå"
[de]="ßüÜäÄÖö"
)

[ -z "$1" ] && return 1

for lan in ${!dd[@]}; do
letters=${dd[$lan]}
len=${#letters}
for (( i = 0; i < len; ++i)); do
letter="${letters:$i:1}"
if [ -z "${1##*$letter*}" ]; then
printf $lan
found=0
break 2
fi
done
done
return $found
}




Alternative?



Is there a better existing alternative for this?



Optionally another tool then xdotool which uses another way of detecting or sending keystrokes?



I have tried guess_language and the like.



Issue is that they are language and not alphabet oriented. As such I get possible false results and single words or short sentences return unknown.










share|improve this question



























  • Can't thing of a much better alternative, even though I would use your strings in regular expressions (for instance, russian would be something like .*[АаБбВвГгДдЕеЁёЖжЗзИиЙйКкЛл†МмНнОоПпРрСсТтУуФфХхЦцЧчШшЩщЪъЫыЬьЭэЮюЯя].*.

    – xenoid
    3 hours ago














0












0








0








Is there some existing tool that can detect keyboard layout needed from string?



As in not language, but layout.



The case



I use xdotool to paste text into an application that does not accept paste.



That is: I use xdotool type … on the text in clipboard.



When I paste for example Russian xdotool detects which layout to use and changes this automatically (from the looks of it).



The detection method is very slow though. The longer the text, the worse.



A string of 130 letters for example takes over 30 seconds when layout needs to be changed.





setxkbmap



I have found that changing the keyboard before using xdotool speeds things up to the normal. For this reason I added a simple layout detection method. It is very crude and is set up only to detect the languages I paste in (beside English).



orig_lang=$(setxkbmap -query | awk '/^layout:/{printf $2}')
lang=$(language "$text")

if [ ! -z "$lang" ] && [[ "$lang" != "$cur_lang" ]]; then
printf "Changing kbmap to %sn" "$lang" >&2
setxkbmap $lang
fi
xdotool type --delay 52 "$text"
if [ ! -z "$lang" ]; then
setxkbmap $orig_lang
fi


``



Where the language function for now is:



language()
{
local -i found=1
local lan
local letters
local letter
local -i len
local -i i
# Note: AaOoPp etc. in ru is not the same as in English
local -A dd=(
[ru]="АаБбВвГгДдЕеЁёЖжЗзИиЙйКкЛл†МмНнОоПпРрСсТтУуФфХхЦцЧчШшЩщЪъЫыЬьЭэЮюЯя"
[no]="ÆØÅæøå"
[de]="ßüÜäÄÖö"
)

[ -z "$1" ] && return 1

for lan in ${!dd[@]}; do
letters=${dd[$lan]}
len=${#letters}
for (( i = 0; i < len; ++i)); do
letter="${letters:$i:1}"
if [ -z "${1##*$letter*}" ]; then
printf $lan
found=0
break 2
fi
done
done
return $found
}




Alternative?



Is there a better existing alternative for this?



Optionally another tool then xdotool which uses another way of detecting or sending keystrokes?



I have tried guess_language and the like.



Issue is that they are language and not alphabet oriented. As such I get possible false results and single words or short sentences return unknown.










share|improve this question
















Is there some existing tool that can detect keyboard layout needed from string?



As in not language, but layout.



The case



I use xdotool to paste text into an application that does not accept paste.



That is: I use xdotool type … on the text in clipboard.



When I paste for example Russian xdotool detects which layout to use and changes this automatically (from the looks of it).



The detection method is very slow though. The longer the text, the worse.



A string of 130 letters for example takes over 30 seconds when layout needs to be changed.





setxkbmap



I have found that changing the keyboard before using xdotool speeds things up to the normal. For this reason I added a simple layout detection method. It is very crude and is set up only to detect the languages I paste in (beside English).



orig_lang=$(setxkbmap -query | awk '/^layout:/{printf $2}')
lang=$(language "$text")

if [ ! -z "$lang" ] && [[ "$lang" != "$cur_lang" ]]; then
printf "Changing kbmap to %sn" "$lang" >&2
setxkbmap $lang
fi
xdotool type --delay 52 "$text"
if [ ! -z "$lang" ]; then
setxkbmap $orig_lang
fi


``



Where the language function for now is:



language()
{
local -i found=1
local lan
local letters
local letter
local -i len
local -i i
# Note: AaOoPp etc. in ru is not the same as in English
local -A dd=(
[ru]="АаБбВвГгДдЕеЁёЖжЗзИиЙйКкЛл†МмНнОоПпРрСсТтУуФфХхЦцЧчШшЩщЪъЫыЬьЭэЮюЯя"
[no]="ÆØÅæøå"
[de]="ßüÜäÄÖö"
)

[ -z "$1" ] && return 1

for lan in ${!dd[@]}; do
letters=${dd[$lan]}
len=${#letters}
for (( i = 0; i < len; ++i)); do
letter="${letters:$i:1}"
if [ -z "${1##*$letter*}" ]; then
printf $lan
found=0
break 2
fi
done
done
return $found
}




Alternative?



Is there a better existing alternative for this?



Optionally another tool then xdotool which uses another way of detecting or sending keystrokes?



I have tried guess_language and the like.



Issue is that they are language and not alphabet oriented. As such I get possible false results and single words or short sentences return unknown.







utilities






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 4 hours ago







user3342816

















asked 4 hours ago









user3342816user3342816

917 bronze badges




917 bronze badges
















  • Can't thing of a much better alternative, even though I would use your strings in regular expressions (for instance, russian would be something like .*[АаБбВвГгДдЕеЁёЖжЗзИиЙйКкЛл†МмНнОоПпРрСсТтУуФфХхЦцЧчШшЩщЪъЫыЬьЭэЮюЯя].*.

    – xenoid
    3 hours ago



















  • Can't thing of a much better alternative, even though I would use your strings in regular expressions (for instance, russian would be something like .*[АаБбВвГгДдЕеЁёЖжЗзИиЙйКкЛл†МмНнОоПпРрСсТтУуФфХхЦцЧчШшЩщЪъЫыЬьЭэЮюЯя].*.

    – xenoid
    3 hours ago

















Can't thing of a much better alternative, even though I would use your strings in regular expressions (for instance, russian would be something like .*[АаБбВвГгДдЕеЁёЖжЗзИиЙйКкЛл†МмНнОоПпРрСсТтУуФфХхЦцЧчШшЩщЪъЫыЬьЭэЮюЯя].*.

– xenoid
3 hours ago





Can't thing of a much better alternative, even though I would use your strings in regular expressions (for instance, russian would be something like .*[АаБбВвГгДдЕеЁёЖжЗзИиЙйКкЛл†МмНнОоПпРрСсТтУуФфХхЦцЧчШшЩщЪъЫыЬьЭэЮюЯя].*.

– xenoid
3 hours ago










0






active

oldest

votes














Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});















draft saved

draft discarded
















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f539897%2fdetect-alphabet-keyboard-layout-from-string%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes

















draft saved

draft discarded



















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f539897%2fdetect-alphabet-keyboard-layout-from-string%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...