Mac / Windows在Javascript中弹出虚拟键盘 [英] Mac/Windows Pop up Virtual Keyboard in Javascript

查看:148
本文介绍了Mac / Windows在Javascript中弹出虚拟键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一款专为大型触摸屏显示器设计的网络应用程序。它不是移动应用程序;它将在Mac OS X和Windows上的FireFox和Chrome中运行。我正在寻找一种方法以编程方式从javascript弹出操作系统的本机屏幕键盘。在Win 7中,这会在用户专注于文本区域时自动发生(就像iOS和Android一样),但对于旧版本的Windows和OS X,用户必须手动将其拉出,这是一件令人讨厌的事情。消除。

I'm working on a webapp that's designed for use on large touchscreen monitors. It is not a mobile app; it will run in FireFox and Chrome on mac OS X and windows. I am looking for a way to programmatically pop up the OS's native on-screen keyboard from javascript. In Win 7, this happens automatically when the user focuses on a text area (just like iOS and Android), but for older versions of Windows and OS X, the user has to manually pull it up, which is a nuisance I would like to eliminate.

理想情况下,它会像Win7 / iOS / Android一样工作,并在用户专注于文本区域时自动弹出,但我会解决任何弹出的javascript键盘,即使我必须为每个文本框添加它。

Ideally, it would work like Win7/iOS/Android and pop up automatically when the user focuses on a text area, but I'll settle for any javascript that pops up the keyboard, even if I have to add it for every text box.

如果这是可能的,我相信Mac与Windows不同,所以我猜这真的是两个问题。任何帮助都表示赞赏。

If this is even possible, I'm sure it's different for Mac vs Windows, so I guess this is really two questions in one. Any help is appreciated.

推荐答案

好的,我已经在我自己的Mac(版本10.6.8)和Windows上进行了本地测试XP所以好消息是它有效(而且非常容易)。

OK, I've tested this locally on my own Mac (version 10.6.8) and Windows XP so the good news is that it works (and it is surprisingly easy).

基本理念是:


  1. 了解如何从命令行打开屏幕键盘

  2. 设置浏览器以允许从JavaScript执行命令行

  3. 写下您的HTML: - )

两个平台的说明如下。

Mac

对于Mac,请下载并构建此Xcode项目:

For Mac, download and build this Xcode project:

  • https://github.com/nriley/keyboardViewer

确保您的构建目标与客户端Mac(例如64位Intel等)相同。输出将是一个名为 keyboardViewer 的可执行文件。这将在执行时弹出屏幕键盘。

Make sure your build target is the same as the client Mac (e.g. 64 bit Intel, etc). The output will be an executable file called keyboardViewer. This will pop open the on-screen keyboard when executed.

假设您已将 keyboadViewer 保存到用户的桌面然后您要执行的命令是(在我的情况下):

Let's assume you've saved keyboadViewer onto the user's Desktop then the command you will want to execute is (as in my case):


  • / Users / Oliver /桌面/ keyboardViewer

  • /Users/Oliver/Desktop/keyboardViewer.

Windows

在Windows上,从命令行打开屏幕键盘要容易得多。以下(或类似)将执行此操作:

On Windows, it is much easier to open the on-screen keyboard from the command line. The following (or similar) will do it:


  • C:\ WINDOWS \ system32 \ osk。 exe

  • C:\WINDOWS\system32\osk.exe

Firefox

接下来,您将不得不从浏览器执行此文件(或Windows命令)。所以,在这里安装Firefox附加组件:

Next, you are going to have to execute this file (or Windows command) from a browser. So, install the Firefox add-on here:

  • https://addons.mozilla.org/en-US/firefox/addon/commandrun/

这个附加组件允许你从JavaScript执行OS命令(例如执行文件)。在从附加组件执行此操作之前,您需要将此命令添加到允许的命令列表中。

This add-on will allow you to execute OS commands (e.g. execute files) from JavaScript. Before you can execute this from the add-on, you will need to add this command to the list of allowed commands.

要执行此操作,请转到 about:config 在浏览器地址栏中。右键单击首选项列表,然后选择新建>字符串。要添加的新首选项的名称是 extensions.commandrun.allowedcommands 。对于该值,请输入以下内容:

To do this, go to about:config in the browser address bar. Right click on the list of preferences and select New > String. The name of the new preference you want to add is extensions.commandrun.allowedcommands. For the value, enter the following:


  • 在Mac上: [/ Users / Oliver / Desktop / keyboardViewer ]

  • 在Windows上: [C:\\ WINDOWS \\system32 \\ osk.exe ]

  • On Mac: ["/Users/Oliver/Desktop/keyboardViewer"]
  • On Windows: ["C:\\WINDOWS\\system32\\osk.exe"]

HTML

现在,您可以使用HTML打开Firefox上的屏幕键盘,如下所示:

Now, you will be able to open the on-screen keyboard from Firefox with HTML like this:

<script language="javascript">
function openKeyboard(){
    CommandRun.run("/Users/Oliver/Desktop/keyboardViewer", []);
}
</script>

<input type="text" onfocus="javascript:openKeyboard();" />

在Windows上,替换以下内容:

On Windows, substitute the following:

CommandRun.run("C:\\WINDOWS\\system32\\osk.exe", []);

替代

另一种方法是在Adobe Air中编写自己的浏览器。使用该方法,您的JavaScript调用您的Air应用程序,然后您的Air应用程序执行 keyboardViewer (或等效的Windows)。

An alternative is to write your own browser in something like Adobe Air. Using that method, your JavaScript calls your Air app and your Air app then executes keyboardViewer (or the Windows equivalent).

这篇关于Mac / Windows在Javascript中弹出虚拟键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆