如何使用Angular代码来使用Windows快捷方式

huangapple go评论74阅读模式
英文:

How to use windows shortcuts using Angular code

问题

在Windows笔记本电脑上,当我们按下"windows + h"时,会打开默认的语音识别功能。
但我想要将这个快捷键设置为单个Angular按钮。
我希望如果我点击按钮,就能打开默认的语音识别,而不是按"windows + h"。
如果有人有任何想法,请建议我。

我正在探索这个功能,但我没有找到任何东西。

英文:

In Windows laptop when we press "windows + h". default voice dictate will open.
But i want this shortcut button on single Angular button.
I want if i click on button that default voice dictate will open instead of pressing windows + h.
If anyone have any idea please suggest me.

I am exploring on that functionality but I did not get anything.

答案1

得分: 1

不能在浏览器中触发操作系统快捷键,因为这可能会造成安全风险。我不认为你能做到这一点_确切地_。

然而,在Chrome和Safari中有一个相关的Web Speech API。它不适用于所有浏览器,而且在不同浏览器上的体验不同(Mac上的Safari使用操作系统内部,Chrome似乎有自己的引擎)。这是一个通用的使用它的文章: https://12daysofweb.dev/2021/speech-api/

一个非常基本的用法可能是:

function logSpeech() {
  const SR = window.SpeechRecognition || window.webkitSpeechRecognition;
  const recognition = new SR();
  recognition.lang = "en-US";


  recognition.onresult = function (event) {
    const transcript = event.results[0][0].transcript;
    console.log(transcript)
  }

  // 在Chrome中,这会自动结束
  recognition.start();
};
英文:

Triggering OS shortcut keys is not possible in a browser as it would be a security risk. I don't think you'll be able to do that exactly.

However there is a related Web Speech API that works in Chrome and Safari. It does not work in all browsers and the experience varies by browser (Safari on Mac uses OS internals, Chrome seems to have its own engine). Here's a generic article on using it: https://12daysofweb.dev/2021/speech-api/

A very-basic use might look like:

function logSpeech() {
  const SR = window.SpeechRecognition || window.webkitSpeechRecognition;
  const recognition = new SR();
  recognition.lang = "en-US";


  recognition.onresult = function (event) {
    const transcript = event.results[0][0].transcript;
    console.log(transcript)
  }

  // in chrome this ends automatically
  recognition.start();
};

huangapple
  • 本文由 发表于 2023年5月25日 13:47:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/76329255.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定