Capturing keyboard input in fullscreen mode does not appear to be functioning

I am currently developing a game using Three.js and I am in need of capturing user input. I have two handler functions set up for this purpose;

function press(evt) 
{
    console.log(evt);

    var code = evt.which || evt.keyCode;

    switch(code) 
    {
        case KEY.W: input.up = true; break;
        case KEY.A: input.left = true; break;
        case KEY.S: input.down = true; break;
        case KEY.D: input.right = true; break;
        case KEY.E: input.e = true; break;
        case KEY.Z: input.z = true; break;
        case KEY.ONE: input.one = true; break;
        case KEY.CTRL: input.ctrl = true; break;
        case KEY.P: input.plus = true; break;
        case KEY.M: input.minus = true; break;
        case KEY.SH: input.shift = true; break;
    }
}

function release(evt)
{
    console.log(evt);

    var code = evt.which || evt.keyCode;

    switch(code) 
    {
        case KEY.W: input.up = false; break;
        case KEY.A: input.left = false; break;
        case KEY.S: input.down = false; break;
        case KEY.D: input.right = false; break;        
        case KEY.E: input.e = false; break;
        case KEY.Z: input.z = false; break;
        case KEY.ONE: input.one = false; break;
        case KEY.CTRL: input.ctrl = false; break;
        case KEY.P: input.plus = false; break;
        case KEY.M: input.minus = false; break;
        case KEY.SH: input.shift = false; break;
    }
}

In my previous projects, both of these functions worked perfectly fine. Here's how I attach the event listeners:

document.addEventListener("keydown", press, false);
document.addEventListener("keyup", release, false);

While everything runs smoothly when the site is loaded normally, it seems to stop functioning properly when switching to fullscreen mode!

This snippet shows the setup within the init(); function, which is triggered by the body onload event:

var init = function()
{
    started = false;
    isFullscreen = false;

    changeFSState = function()
    {
        if (isFullscreen == true)
        {
            isFullscreen = false;

            game.stop(); //lol
        }
        else
        {
            isFullscreen = true;
        }
    }

    container = document.getElementById("container");
    document.body.appendChild(container);

    document.addEventListener("keydown", press, false);
    document.addEventListener("keyup", release, false);

    document.addEventListener("webkitfullscreenchange", changeFSState, false);
    document.addEventListener("mozfullscreenchange", changeFSState, false);

    game = new Game(container);
}

When the play button is clicked, the following happens:

THREEx.FullScreen.request(self.container);  
self.renderer.setSize(screen.width, screen.height);

However, after clicking the play button (which is actually a link), the input events are no longer being logged in the console - as if they are not being triggered at all.

Answer №1

The THREEx.FullScreen plugin appears to be utilizing the following code snippet:

element.webkitRequestFullScreen();

However, what you actually require is:

element.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);

It seems like this feature is limited to Chrome.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for converting API data to DTO (Data Transfer Object) using TypeScript

Here is an array of vehicles with their details. export const fetchDataFromApi = () => { return [ { vehicleId: 1, vehicleType: 'car', seats: 4, wheelType: 'summer', updatedAt: new Date().toISOString }, { vehicleId: 2, vehic ...

Node.js Application with Role-Based Login

I am currently working on implementing role-based administration. When a user is created, the database stores a "1" for Admin or a "2" for a normal user. I want to retrieve this information from the database and display the corresponding start page based o ...

What steps can I take to verify that all textboxes are filled and checkboxes are selected before allowing the user to submit the form?

Here is the JavaScript code and a snippet of the HTML that I am using to create a form. I am having trouble figuring out why the form can still be submitted even when there are empty fields. Ideally, a dialog box should pop up indicating which fields nee ...

Exploring Vue.prototype attributes and utilizing them

I'm facing a challenge while attempting to globally set a property using Vue.prototype. This is what I currently have: microsoftTeams.initialize(); microsoftTeams.getContext((context) => { Vue.prototype.$teamsContext = true; }); new Vue({ ...

Is it possible to adjust the height of the apprequests dialog?

I attempted the following code snippet: FB.UIServer.Methods["apprequests"].size = {width:600,height:320}; The width successfully adjusts, however, the height is restricted to a fixed value. Appreciate any help! ...

$stateParams is not being properly defined when passed to the controller

I am currently utilizing ui-router to transfer an object to another state and controller by using $state.go() However, when I check the console.log for the $stateParams object, it appears as undefined. The object consists of x and y coordinates which ar ...

Spin around a particular point of rotation

Struggling to pivot a headphone set piece. Easy in Maya, but not in threejs. https://i.sstatic.net/WOwvT.png Know how to rotate X Y Z like this: object.rotateX(THREE.Math.degToRad(degreeX)); object.rotateY(THREE.Math.degToRad(degreeY)); object.rotateZ(T ...

Rearrange the items in an array that contain different data types

After spending some time searching on SO, I did find some helpful information but I am still struggling to achieve the desired solution. My current issue involves a keypad with numbers 1 through 5. When a number key is selected, it gets added to an array n ...

If the window width is less than the specified value, hide the DIV and replace it with a

I came across a discussion about hiding a div if the screen is narrower than 1024px, and I'm looking to implement something similar based on the quoted code below. Essentially, I want to hide one div (id="krug_wide") if the window width is less than 1 ...

Issue with Tooltip Position when Scrolling Sidebar is causing display problems

My goal is to create a Sidebar with Tooltip attached to its <li> elements similar to this example: Screenshot - Good Tooltip However, I am facing an issue where the position of the Tooltip breaks when scrolling to the bottom of the sidebar, causing ...

I am struggling to make the while loop in JavaScript stop even when I command it to

var dataStatus = '1'; while (dataStatus != 0) { $.ajax({ url: '/ajax.php?updateData='+dataStatus, dataType: 'json', async: false, success: function(response) { dataStatus = respo ...

Exploring Rxjs through fundamental queries

Currently, I am working on a small application using Angular 2 and have installed Rxjs 5. However, I have encountered various ways of importing the Rxjs library in tutorials. The code mentioned in the Angular 2 documentation is not functioning properly i ...

Stop click event from firing on a disabled tree node within an angular custom directive template

In the browser, my custom Angular tree component is displayed like this: + Parent 1 + Child 1-A - Child 1-A-A - Child 1-A-B - Child 1-A-C + Child 1-B + Child 1-C This is what the directive template looks like: <ul> &l ...

There seems to be an issue with the HighCharts Pie Chart where the total value is not

I'm struggling to show the total number of users on the PieChart. Unfortunately, my code for "getting the total" isn't working as expected and nothing is being displayed. Here's the code snippet I'm using: events: { load: func ...

Activating/Deactivating Checkbox using Jquery

I'm having trouble getting this code to function properly when there are multiple instances of datepicker on the page. When selecting the option "I currently work here," it is affecting all groups instead of just the current one, which is not the des ...

We are experiencing a peculiar issue with the camera functionality in ThreeJS

I have created a scene in ThreeJS featuring two cubes, a camera, a light, and a plane. The cubes rest on the plane while the camera gracefully circles around the green cube. Despite my efforts, I am encountering an unusual issue with the camera angles. As ...

Troubleshooting Angular Reactive Forms: Issue with Binding Dynamic Select Dropdown Value

I currently have two arrays of data: AssociatedPrincipals, which contains previously saved data, and ReferencePrincipals, which consists of static data to populate dropdown controls. I am facing difficulties in displaying/selecting the previous value from ...

One array comprises of all elements found in a separate array

After grappling with this problem for a while, I still haven't been able to find a solution. If I have 2 arrays structured like this: array1 = [ { name: 'John', age : 25}, { name: 'Jane', age : 58} ] array2 = [ { name: ...

Tips on incorporating redirect link to Material UI icon's onclick in React

I'm encountering some issues when trying to add a function to the VideocamOutlinedIcon on line 232. I want this function to include an onclick event that redirects the user to an external domain link in a new tab. Despite attempting various solutions, ...

What is the issue with the character set?

Attempting to send request data from JavaScript to Java using JSON format. In JavaScript, the request body appears as: { "id": "3", "name": "Chicken pasta", "description": "Lets make chicken pasta", "category": "Unassigned", "favorite" ...