MacOS在光标下的JavaScript抓词中强制触摸事件

时间:2019-04-28 15:49:44

标签: javascript macos force-touch

我正在寻求创建一个野生动物园扩展程序来扩展强制触摸功能。我已经阅读了文档,并编写了一些代码来确定是否发生了强制触摸。现在,我需要采取的下一步是将单词放在光标下,但文档中对此一无所知。

function forceChanged(event)
    {
      // Perform operations in response to changes in force

      getEventData(event);
    }

    function setupForceClickBehavior()
    {

      let element = document.getElementById("my_paragraph_element");

      console.log(meme);

      // Attach event listeners in preparation for responding to force clicks
      element.addEventListener("webkitmouseforcewillbegin", prepareForForceClick, false);
      element.addEventListener("webkitmouseforcedown", enterForceClick, false);
      element.addEventListener("webkitmouseforceup", endForceClick, false);
      element.addEventListener("webkitmouseforcechanged", forceChanged, false);
    }

function getEventData(event)
    {
      // Check to see if the event has a force property
      if ("webkitForce" in event)
      {
        // Retrieve the force level
        var forceLevel = event["webkitForce"];

        // Retrieve the force thresholds for click and force click
        var clickForce = MouseEvent.WEBKIT_FORCE_AT_MOUSE_DOWN;
        var forceClickForce = MouseEvent.WEBKIT_FORCE_AT_FORCE_MOUSE_DOWN;


         if (forceLevel >= forceClickForce) {
        // Perform operations in response to a force click

          console.log("force touch happened")
      }
    }

我希望找到一种方法来使单词成为光标。

0 个答案:

没有答案