Jump to content

Overriding TheInput's methods? (Or: fixing Alt key stuck pressed after alt-tabbing)


myxal

Recommended Posts

Apparently, there's an issue with Windows builds of DST and DS, where if one alt-tabs out of the game, with default keybinds, the game in background will continue to see the Alt (CONTROL_FORCE_INSPECT) pressed down until it regains focus. (I can't really tell on the Mac, as the cmd key cannot be assigned to a control at all, and Alt-tab obviously doesn't task-switch away from the game). This is a problem for me because it causes playeractionpicker:GetClickActions to shuffle the actions around from left-click to right-click etc.

In eXiGe's DST version of ActionQueue Reborn, he fixed this by overriding components/playercontroller:IsControlPressed method to not report the Alt key as pressed when an action queue was active. The question is, how to put this in singleplayer? The method in DS is in TheInput, which I assume is an instance of the class in input.lua, so I thought something like this would work: 

AddClassPostConstruct("input", function(self)
  DebugPrint("AQR: AddClass - Input")
  local InputIsControlPressed = self.IsControlPressed
  self.IsControlPressed = function(self, control)
    DebugPrint("AQR: InputIsControlPressed override")
    if control == CONTROL_FORCE_INSPECT and ActionQueuer and ActionQueuer.action_thread then return false end
    return InputIsControlPressed(self,control)
  end
end)

... but it doesn't even execute the first function, judging by the lack of the first debugprint output. What do I need to do to override methods in TheInput?

Or is overriding Input methods a dead end, and I should find another solution? (I'm thinking of ignoring the Alt in the playeractionpicker, by returning rightclick actions to a query for left-click actions, when the "AQ running" condition is met.)

Link to comment
Share on other sites

 

I went with the last idea, seems to work fine (with actually holding alt in the Mac version of the game):

AddComponentPostInit("playeractionpicker", function(self, inst)
  self.GetLeftClickActions = function(self,a,b)
    if TheInput:IsControlPressed(CONTROL_FORCE_INSPECT) and ActionQueuer and ActionQueuer.action_thread then
      return self:GetRightClickActions(b,a)
    else
      return self:GetClickActions(b,a)
    end
  end
end)

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...