special characters - How can I find the Alt KeyCode for a glyph with the Windows system tools? - Super User


how can find alt keycode of particular glyph (special character) using standard utility ships windows (or ?command line statement?)?

i understand might seem duplicate of find alt code character

however, noted @tomáš in comments @rik's post, not show alt keycode all characters (especially of useful ones, i.e. arrows, smileys...etc)

full description of windows alt+x codes

based on short details on alt codes (the best article have seen yet although incomplete).

for given (decimal) number x between 1 , 65535, alt code resultant character depends on range (1..31,32..127, 128..255, 256..65535) , may needn't depend on:

  • number format, leading zero(es) presence: alt+x versus alt+0x
  • application unicode facility:
    • legacy (code-page based, non-unicode), e.g. cmd, powershell, notepad, …
    • unicode, e.g. wordpad (write), sticky notes (stikynot), search box in explorer, …
  • system locale: determines ansi, oem , mac codepages , associated bitmap font files used defaults system.
  • input locale, pair consisting of language user wants input , method of input (narrowed down keyboard here):
    • language;
    • keyboard layout.

range specific rules - alt+x

from    to result: x-th character …
  1     31 … string ☺☻♥♦♣♠•◘○◙♂♀♪♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼
 32    127 … oem/ansi code page (identical locale in range)
128    255 … oem code page default system locale
256  65535 legacy: apply above rules x % 256 (see modulo operation)
           unicode: … unicode table

range specific rules - alt+0x

from      to result: x-th character …
  01     031 … unicode table (control characters); check alt+09 character tabulation
 032    0127 … ansi/oem code page (identical locale in range)
0128    0255 legacy: … ansi code page default keyboard layout regardless of language
             unicode: … ansi code page default language regardless of keyboard layout
0256  065535 legacy: apply above rules x % 256 (including leading zero)
             unicode: … unicode table (regardless of leading zero)

i found , double checked described rules using next testing input locales (see test_get-culture.ps1 script below):

    language  l.tag     kbdid keyboard layout     --------  -----  -------- ---------------      english  en-gb  00000809 united kingdom      english  en-gb  00000405 czech        czech     cs  00000405 czech        czech     cs  00020409 united states-international modern greek     el  00000408 greek      russian     ru  00000419 russian      turkish     tr  0000041f turkish q      turkish     tr  00000426 latvian     estonian     et  0000041b slovak     estonian     et  0001041f turkish f 

slightly impractical language keyboard layout combinations, isn't it? however, above rules seem ready script them…

alt keycode finder

param([string[]] $inobject = @([char] 0x0)) function getasciicode ([char] $gacchar, [int] $gaccode) {     if ($gaccode -le 0) {         $gacachar = [byte[]] 0         $gacpinto = [byte[]] 0         $gacpi437 = [byte[]] 0     } else {         $gaceunic = [system.text.encoding]::getencoding(1200)         $gacet437 = [system.text.encoding]::getencoding(437)         $gacetarg = [system.text.encoding]::getencoding($gaccode)         $gacachar = $gaceunic.getbytes($gacchar)         $gacpinto = [system.text.encoding]::convert($gaceunic,$gacetarg,$gacachar)         $gacpfrom = [system.text.encoding]::convert($gacetarg,$gaceunic,$gacpinto)         $gacpi437 = [system.text.encoding]::convert($gaceunic,$gacet437,$gacachar)         if ( -not ( $gacchar -eq $gaceunic.getstring($gacpfrom) -or $gacpinto -le 31 ))              { $gacpinto = [byte[]] 0 }         <#         if ($gacchar -eq '§') {             write-host "abc- " -nonewline             write-host $gaccode, achar, $gacachar, pinto, $gacpinto, pfrom, $gacpfrom, pi437, $gacpi437 -nonewline             write-host " -def"         }         #>     }     switch ($gacpinto.count) {         2 { # double-byte character set (dbcs) recognized             [int32] $gacpinno = $gacpinto[1]+$gacpinto[0]*256             # [int32] $gacpinno = 0           }         1 { # single-byte character set (sbcs) recognized             [int32] $gacpinno = $gacpinto[0]           }         default { [int32] $gacpinno = 0 }     }     return @($gacpinno, $gacpi437[0]) }  <# language groups   : https://msdn.microsoft.com/en-us/goglobal/bb688174 input method (ime): get-winuserlanguagelist language examples : https://www.microsoft.com/resources/msdn/goglobal/default.mspx code pages & lcids: [system.globalization.cultureinfo]::getcultures(                     [system.globalization.culturetypes]::allcultures)|                         format-custom -property displayname, textinfo #> $kbdlayouts = @(    # basic collection (installed on languages of os)     @('0409', 437, 1252, 'en-us',  1, 'us & western eu'),     @('0809', 850, 1252, 'en-gb',  1, 'us & western eu'),     @('0405', 852, 1250, 'cs-cz',  2, 'central europe'),     @('0425', 775, 1257, 'et-ee',  3, 'baltic'),     @('0408', 737, 1253, 'el-gr',  4, 'greek'),     @('0419', 866, 1251, 'ru-ru',  5, 'cyrillic'),     @('041f', 857, 1254, 'tr-tr',  6, 'turkic'),    # east asian collection: double-byte character sets (dbcs):      #@('0411',   0,  932, 'ja-jp',  7, 'japanese'),     # (japan),  dbcs     #@('0412',   0,  949, 'ko-kr',  8, 'korean'),       # (korea),  dbcs     #@('0404',   0,  950, 'zh-tw',  9, 'trad. chinese'),# (taiwan), dbcs     #@('0804',   0,  936, 'zh-cn', 10, 'simpl.chinese'),# (china),  dbcs    # complex script collection (always installed on arabic , hebrew localized oses)       @('041e',   0,  874, 'th-th', 11, 'thai'),         # (thailand)     @('040d', 862, 1255, 'he-il', 12, 'hebrew'),       # (israel)     @('0c01', 720, 1256, 'ar-eg', 13, 'arabic'),       # (egypt)     @('042a',   0, 1258, 'vi-vn', 14, 'vietnamese'),   # (vietnam)    # unknown supported code page    #@('0445',   0,    0, 'bn-in', 15, 'indic'),        # bengali (india)    #@('0437',   0,    0, 'ka-ge', 16, 'georgian'),     # (georgia)    #@('042b',   0,    0, 'hy-am', 17, 'armenian'),     # (armenia)     @('0000',  -1,   -1, 'xx-xx', 99, 'dummy entry'))  # (last array element - not used)    #@(lcid, oem-cp, ansi-cp, imetxt, groupno, grouptxt) $currentlocale = get-winsystemlocale $currentime    = "{0:x4}" -f $currentlocale.keyboardlayoutid $currentocp    = (get-itemproperty "hklm:\system\currentcontrolset\control\nls\codepage").oemcp $currentacp    = (get-itemproperty "hklm:\system\currentcontrolset\control\nls\codepage").acp $currenthead   = 'ime ' + $currentime + '/' + $currentlocale.name +      "; cp" + $currentocp + "; ansi " + $currentacp $currheadcolor = "cyan" $currcharcolor = "yellow" # write header $inobject write-host $("{0,2} {1,7} {2,7} {3,12}{4,7}{5,7}" -f `    "ch", "unicode", "alt?", "cp    ime", "alt", "alt0") -nonewline write-host $("    {0}" -f $currenthead) -foregroundcolor $currheadcolor [string] $sx = '' ($i = 0; $i -lt $inobject.length ; $i++) {     [char] $saux = [char] 0x0     [string] $sinx = $inobject[$i]     if ($sinx -eq '') { [string] $sinx = [char] 0x00 }     try {   [int] 0 + $sinx | out-null             [char] $saux = $sinx | invoke-expression         }     catch { [string] $saux = ''} #finally {#$sinx    += $saux }     if ($saux -eq '') { $sx += $sinx } else { $sx += $saux } }  ($i = 0; $i -lt $sx.length ; $i++) {    [char] $ch = $sx.substring($i,1)    $chint = [int] $ch    $chmodulo = $chint%256    $altpdesc = "…$chmodulo…"    try {            # get-charinfo module downloadable http://poshcode.org/5234        #        add current session: use import-module cmdlet        $ch | get-charinfo |% {            $chucode = $_.codepoint            $chctgry = $_.category            $chdescr = $_.description        }    }    catch {        $chucode = "u+{0:x4}" -f $chint        if ( $chint -le 0x1f -or ($chint -ge 0x7f -and $chint -le 0x9f))              { $chctgry = "control" } else { $chctgry = "" }        $chdescr = ""    }    { $chout = $ch }    $altpcode = "$chint" # possible  alt+ code     $altrcode = ""       # effective alt+ code    $altrzero = ""       # effective alt+0 code    if ( $chctgry -eq "control" ) { # possibly non-printable character       $chout = ''              $altpcode = ""       if ($chint -gt 0) { $altrzero = "0$chint" }     } else {       $chout = $ch                 # supposedly printable character       if ($chint -le 127) {          $altrzero = "0$chint"          $altrcode = "$chint"       }    }    write-host "" # better output readability?    write-host ("{0,2} {1,7} {2,7} {3,12}{4,7}{5,7}" -f `       $chout, $chucode, $altpcode, $altpdesc, $altrcode, $altrzero) -nonewline    write-host ("    {0}" -f $chdescr) -foregroundcolor $currcharcolor    $altrcode = ""    if ($chint -gt 127) {       ($j = 0; $j -le ($kbdlayouts.length -1) ; $j++) {          $altpcode = ""          $altrcode = ""          $altrzero = ""          [int] $acp = $kbdlayouts[$j][2]    # ansi code page          $aacode = getasciicode $ch $acp          $xxcode = $aacode[0]          if ($xxcode -eq 0) {} else { $altrzero = "0$xxcode" }          [int] $ocp = $kbdlayouts[$j][1]    # oem code page          $oocode = getasciicode $ch $ocp          $yycode = $oocode[0]          if ($yycode -eq 0) { } else { $altpcode = "$yycode" }          if (($altpcode + $altrzero) -ne "") { # locale-dependent line             $chout = ""             $chucode = ""             if ($ocp -le 0) { $altpdesc = ''   #  not valid oem cp             } else          { $altpdesc = ('cp' + [string]$ocp)             }             $altpdesc += ($kbdlayouts[$j][3].padleft(6))            #if ($kbdlayouts[$j][0] -eq $currentime -or $yycode -le 128) {             if ($ocp -eq [int]$currentocp -or $yycode -le 128) {                 if ($yycode -eq $oocode[1]) { $altrcode = $altpcode }             }             if ($oocode[1] -ge 1 -and $oocode[1] -le 31 -and $altrcode -eq "") {                 $altrcode = $oocode[1]             }             if ($acp -gt 0) {                 $alt0desc = '(ansi' + ([string]$acp).padleft(5) +                               ') ' + $kbdlayouts[$j][5].padright(16)             } else {                 $alt0desc = ''             }             if ($ocp -eq [int]$currentocp -and  $altrcode -eq "") {                 $altrcode =  $altpcode             }             $line = "{0,2} {1,7} {2,7} {3,12}{4,7}{5,7}    {6}" -f `                 $chout, $chucode, $altpcode, $altpdesc, $altrcode, $altrzero, $alt0desc             if ($ocp -eq [int]$currentocp) {                 write-host $line -foregroundcolor $currheadcolor             } else {                 write-host $line             }          }        }    } } # write footer write-host `r`n($inobject -join ",") -foregroundcolor $currcharcolor if ($sx -eq '') {                     # simple    $aux = $myinvocation.invocationname    "usage  : $aux [<string>]`r`n"    "column :  description of character base line"    write-host "       : -description of locale-dependent lines" -nonewline    write-host " (coloured system defaults)" -foregroundcolor $currheadcolor    "-------"    "ch     :  character if printable"    "unicode:  character code (unicode notation)"    "alt?   :  character code (decimal) = alt+ code if <=127 or > 255 (unicode apps)"    "       : -alt+ code if following cp , ime corresponds system default oem-cp"    "cp     : -oem code page corresponding input method"    "ime    :  …character code modulo 256… (note surrounding ellipses)"    "       : -keyboard layout (input method) (text)"    "alt    : -effective alt+  code complying system default oem-cp request"    "alt0   : -effective alt+0 code ime corresponding ansi-cp"    write-host "ime    :  unicode name of character " -nonewline    write-host "(only if activated get-charinfo module)" -foregroundcolor $currcharcolor    "         -(ansi codepage) laguage group name`r`n"    #write-host "" } 

does not apply "unicode only" languages such hindi , georgian.

sample output: mycharmap 0xfd,ěìμм,291. characters chosen show different alt+0236 results in different input locales.

alt keycode finder

appendix1: mycharmap.bat script:

@powershell import-module d:\pshell\get-charinfo_1.1.ps1;d:\pshell\su\1024763.ps1 %* 

appendix2: test_get-culture.ps1 script:

### test_get-culture.ps1 ### "{0,20}  {1,5}  {2,8} {3}" -f "language", "l.tag", "kbdid", "keyboard layout" "{0,20}  {1,5}  {2,8} {3}" -f "--------", "-----", "--------", "---------------" $gcwull = get-winuserlanguagelist $gcwull | foreach-object {     $gcu=$_     $gcuimt=$gcu.inputmethodtips      write-output $gcuimt | foreach-object {         $clx=$_.substring(5)         $clz=get-item -literalpath "hklm:system\currentcontrolset\control\keyboard layouts\$clx"         $cly=$clz.getvalue("layout text", $gcu.languagetag)         "{0,20}  {1,5}  {2,8} {3}" -f ($gcu.englishname).replace(' (1453-)',''), $gcu.languagetag, $clx, $cly     } } 

Comments

Popular posts from this blog

download - Firefox cannot save files (most of the time), how to solve? - Super User

windows - "-2146893807 NTE_NOT_FOUND" when repair certificate store - Super User

sql server - "Configuration file does not exist", Event ID 274 - Super User