65.9K
CodeProject 正在变化。 阅读更多。
Home

Agochar 输入法 - 印地语虚拟键盘

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.76/5 (10投票s)

2008年5月8日

CPOL
viewsIcon

94832

downloadIcon

3025

一个紧凑的 InScript 虚拟键盘,用于在文本框中输入印地语(印度官方语言)字符。

引言

我实现了一个虚拟键盘,用于将 En/US 布局转换为印地语 InScript(印度脚本)键盘叠加层,该叠加层由 DOE 于 1986 年标准化。

背景

本文演示了一个印地语(印度官方语言)的虚拟键盘。 在此,我们使用包含所有可能的印地语字符的图像,然后生成一个映射来捕获鼠标在图像上的移动。

<div style="z-index:0;position:absolute; top:0px; left:0px;">
<img src="images/Base_kbd.gif" border="0" usemap="#Map" />
// here, a map having name "Map" is attached with image

<map name="Map" id="Map">// here, we create a map to handel mouse click on image

  <area shape="rect" coords="/*Left*/280,/*Top*/0,/*Right*/300,/*Bottom*/19" 
        onclick="alert('Back Space - Not Implemented!');" />
  <area shape="rect" coords="271,20,300,39" 
        onclick="alert('Delete - Not Implemented!');" /> // handel Delete 
  <area shape="rect" coords="257,40,300,59" 
        onclick="alert('Enter - Not Implemented!');" /> // handel Enter 
  <area shape="rect" coords="-6,61,46,80" 
        onmousedown="IsShift=!IsShift;reset();"/> // handel Left Shift 
  <area shape="rect" coords="247,61,300,79" 
        onmousedown="IsShift=!IsShift;reset();"/> // handel Right Shift 
  <area shape="rect" coords="81,82,196,99" onmousedown="InsertChar('m',32)" 
        onmouseup="ButtonUp(32)"/> // handel Space Bar 

</map>
</div>

为了捕获浏览器级别的键盘事件,如 KeyPressKeyUpKeyDown,我们使用 addEventListener

<div style="z-index:0;position:absolute; top:103px; left:0px;">
    <input type="text" id="txtHindi" name="txtHindi" 
      style="width:295px; height:30px;"/>
    </div>

<script>
if(navigator.appName!= "Mozilla") // if the browser is not Mozilla
{
  document.getElementById('txtHindi').onkeydown=checkCode;
  document.getElementById('txtHindi').onkeypress=writeKeyPressed;
  document.getElementById('txtHindi').onkeyup=restoreCode;
}
else
{
  document.addEventListener("onkeydown",checkCode,true);
  document.addEventListener("onkeypress",writeKeyPressed,false);
  document.addEventListener("onkeyup",restoreCode,true);
}
</script>

使用代码

为了方便使用,我将两个单独的 zip 文件附加到本文中。 一个只包含默认页面,这是本文的重点。 另一个是展示如何在自己的网页中使用它。

键码和对应的字符

var VirtualKey = {
'113':'&#2380;','119':'&#2376;','101':'&#2366;','114':'&#2368;',
'116':'&#2370;','121':'&#2348;','117':'&#2361;',
'105':'&#2327;','111':'&#2342;','112':'&#2332;',
'97':'&#2379;','115':'&#2375;','100':'&#2381;','102':'&#2367;',
'103':'&#2369;','104':'&#2346;','106':'&#2352;',
'107':'&#2325;','108':'&#2340;',
'122':'','120':'&#2306;','99':'&#2350;','118':'&#2344;',
'98':'&#2357;','110':'&#2354;','109':'&#2360;',
'81':'&#2324;','87':'&#2320;','69':'&#2310;','82':'&#2312;',
'84':'&#2314;','89':'&#2349;','85':'&#2329;',
'73':'&#2328;','79':'&#2343;','80':'&#2333;',
'65':'&#2323;','83':'&#2319;','68':'&#2309;','70':'&#2311;',
'71':'&#2313;','72':'&#2347;','74':'&#2353;',
'75':'&#2326;','76':'&#2341;', '90':'','88':'&#2305;','67':'&#2339;',
'86':'','66':'','78':'&#2355;','77':'&#2358;',
'96':'`','49':'1','50':'2','51':'3','52':'4','53':'5','54':'6',
'55':'7','56':'8','57':'9','48':'0','45':'-',
'61':'&#2371;','92':'&#2377;',
'91':'&#2337;','93':'&#2364;',
'59':'&#2330;','39':'&#2335;',
'44':',','46':'.','47':'&#2351;',
'126':'','33':'&#2317;','64':'&#2373;','35':'&#2381;',
'36':'&#2352;&#2381;','37':'&#2332;&#2381;&#2334;',
'94':'&#2340;&#2381;&#2352;','38':'&#2325;&#2381;&#2359;',
'42':'&#2358;&#2381;&#2352;','40':'(','41':')',
'95':'&#2307;','43':'&#2400;','124':'&#2321;',
'123':'&#2338;','125':'&#2334;',
'58':'&#2331;','34':'&#2336;',
'60':'&#2359;','62':'&#2404;','63':'&#2399;', '32':' '};

这些字符的图像

agochar-keypad

关注点

要将这些代码用于任何其他语言,您需要生成新的图像,然后更新键码和对应字符的数组。

历史

  • 2008 年 5 月 8 日 - 首次发布。
© . All rights reserved.