使用控制器进行导航在打开控制器后无法工作。

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

Navigation using Controller doesn't work after turning on the controller

问题

抱歉,我只能为您提供翻译的文本,不提供其他内容。以下是您要翻译的内容:

"Hi I'm trying to develop a UWP WebView App for XBOX using the web source URL. Currently, the app is working fine. But when we don't do any navigation using the Gamepad for a long time. The controller is turned off automatically. When we turn it on again we are not able to move the focus for some time and none of the key actions will work.

Is there any workaround that can be used to fix this issue. Since the focus will not work for sometime after the XBOX controller is turned on again.

We're using the Gamepad API to handle the focus navigation issue and VS2022 is being used to develop the UWP WebView App using C#.

Thanks in advance. Happy coding."

英文:

Hi I'm trying to develop a UWP WebView App for XBOX using the web source URL. Currently, the app is working fine. But when we don't do any navigation using the Gamepad for a long time. The controller is turned off automatically. When we turn it on again we are not able to move the focus for some time and none of the key actions will work.

Is there any workaround that can be used to fix this issue. Since the focus will not work for sometime after the XBOX controller is turned on again.

We're using the Gamepad API to handle the focus navigation issue and VS2022 is being used to develop the UWP WebView App using C#.

Thanks in advance. Happy coding.

答案1

得分: 2

为了正确使用游戏手柄,即在Webview控件中滚动浏览一些内容,您需要将一些javascript代码注入到Webview中,结合您的HTML内容。我最近在负责的一台生产Xbox中遇到了这个确切的问题。

问题是将使用条款HTML加载到Webview中,并允许用户使用游戏手柄滚动浏览。

解决方法是将HTML内容加载到变量中,然后将javascript内容(也存储在字符串变量中)和HTML注入到Webview中。javascript的执行是启用游戏手柄的关键。

using (var wc = new HttpClient())
{
    var html = await wc.GetStringAsync(new Uri(ContentUrl));
    var script = @"<script>
    navigator.gamepadInputEmulation = 'gamepad'; 
    window.external.notify(navigator.gamepadInputEmulation);
    var x = document.body;
    function ScrollUp() { document.body.scrollTop -= 100; }
    function ScrollDown() { document.body.scrollTop += 100; }
    </script></body>";

    ContentWebView.NavigateToString(html + script);                    
}

所需的关键javascript代码是:

navigator.gamepadInputEmulation = 'gamepad'; 
window.external.notify(navigator.gamepadInputEmulation);
英文:

In order to use the Gamepad correctly. I.e. to scroll through some content in a Webview control, you need to inject some javascript code into the webview in combination with your html content. I recently faced this exact issue in a production Xbox I am responsible for.

The issue was loading terms of use html into a webview and allowing user to scroll through it using the gamepad.

The solution was to load the html content into a variable. Then inject javascript content (also stored in string var) and html into the webview. The execution of the javascript being what enables the gamepad.

using (var wc = new HttpClient())
{
    var html = await wc.GetStringAsync(new Uri(ContentUrl));
    var script = @&quot;&lt;script&gt;
navigator.gamepadInputEmulation = &#39;gamepad&#39;; 
window.external.notify(navigator.gamepadInputEmulation);
var x = document.body;
function ScrollUp() { document.body.scrollTop -= 100; }
function ScrollDown() { document.body.scrollTop += 100; }
&lt;/script&gt;&lt;/body&gt;&quot;;

    ContentWebView.NavigateToString(html + script);                    
}

The key javascript code needed is:

navigator.gamepadInputEmulation = &#39;gamepad&#39;; 
window.external.notify(navigator.gamepadInputEmulation);

huangapple
  • 本文由 发表于 2023年7月17日 16:26:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/76702662.html
匿名

发表评论

匿名网友

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

确定