Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Disable User Keyboard input

Discussion in 'The Lab' started by Tasyen, Dec 2, 2019.

  1. Tasyen

    Tasyen

    Joined:
    Jul 18, 2010
    Messages:
    1,694
    Resources:
    37
    Tools:
    2
    Maps:
    3
    Spells:
    11
    Tutorials:
    20
    JASS:
    1
    Resources:
    37
    This is an working version of an idea: disabling the keyboard input for specific players. It works by giving the keyboard focus to an EditBox. That focus is reapplied multiple times a second.
    This disabling can be bypassed by the user by spamming the esc Button, the wanted hotkey and a mouse click. Although it still requires multiple seconds and dozens of tries to use the hotkey (quite much effort for one activation). This does not block the mouse input.
    Code (Lua):
    do
        local timer = CreateTimer()
        local frame
        -- the players having hotkeys disabled
        local disablePlayers = {}
        TimerStart(timer, 0.0, false, function()
            -- create the Frame keeping the Keyboard focus
            frame = BlzCreateFrameByType("EDITBOX", "", BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0), "", 0)
            BlzFrameSetSize(frame, 0.001, 0.001)
            BlzFrameSetAbsPoint(frame, FRAMEPOINT_BOTTOMLEFT, 0.001, 0.001)

            -- Reapply the focus to the frame for the wanted players
            TimerStart(timer, 0.01, true, function()
                if disablePlayers[GetLocalPlayer()] then
                    BlzFrameSetFocus(frame, true)
                end
            end)
        end)
        function DisableHotkeys(player, flag)
            disablePlayers[player] = flag
            if GetLocalPlayer() == player then
                BlzFrameSetFocus(frame, flag)
                BlzFrameSetVisible(frame, flag)
                BlzFrameSetEnable(frame, flag)
            end
        end
    end
     
    after one uses:
    DisableHotkeys(Player(0), true)
    . Player Red won't be able to chat nor use any hotkey.
     
  2. Clanzion

    Clanzion

    Joined:
    Jul 4, 2016
    Messages:
    454
    Resources:
    0
    Resources:
    0
    Would it be possible to disable a specific key rather than all?
     
  3. Tasyen

    Tasyen

    Joined:
    Jul 18, 2010
    Messages:
    1,694
    Resources:
    37
    Tools:
    2
    Maps:
    3
    Spells:
    11
    Tutorials:
    20
    JASS:
    1
    Resources:
    37
    Not with this technique.
     
  4. apsyll

    apsyll

    Joined:
    Aug 28, 2015
    Messages:
    212
    Resources:
    1
    Maps:
    1
    Resources:
    1
    Couldn't you use the mouse pressed and player skip cinematic natives to hook into to let the player focus again to your frame? So it should be impossible for them even with spam-clicking.
     
  5. Tasyen

    Tasyen

    Joined:
    Jul 18, 2010
    Messages:
    1,694
    Resources:
    37
    Tools:
    2
    Maps:
    3
    Spells:
    11
    Tutorials:
    20
    JASS:
    1
    Resources:
    37
    Will test that. But there might be a problem with network play which is not existing when only using a timer.
     
  6. SinisterLuffy

    SinisterLuffy

    Joined:
    Apr 8, 2020
    Messages:
    99
    Resources:
    0
    Resources:
    0
    @Tasyen Yo, did you ever test @apsyll's hypothesis? Is there a way to separate disabling chat from disabling command card?

    And do you have anything for mouse input?
     
  7. Tasyen

    Tasyen

    Joined:
    Jul 18, 2010
    Messages:
    1,694
    Resources:
    37
    Tools:
    2
    Maps:
    3
    Spells:
    11
    Tutorials:
    20
    JASS:
    1
    Resources:
    37
    I got another more simple Idea to disable user input. One makes the Player an observer. As observers are not allowed to give orders.
    Disable Input.
    call SetPlayerState(Player(0), PLAYER_STATE_OBSERVER, 1)

    Reverse the disabled Input
    call SetPlayerState(Player(0), PLAYER_STATE_OBSERVER, 0)


    Has some sideeffects though:
    The player also can not trigger any sync events anymore (can't end it from the target player poistion).
    It changes the upkeep text for that player.
    The game saves the units one had selected before becoming a Observer and remembers it. Then when becoming a real Player again and giving Orders the remembered units will do the orders aswell (without being selected UI wise)
    Until one selects and deselects them.
     
    Last edited: Nov 25, 2020 at 1:14 PM