Keeping button pressed

Announcements, questions
Post Reply
AnnaV
Posts: 8
Joined: 17 Jan 2019, 20:41

Keeping button pressed

Post by AnnaV » 26 Jan 2019, 09:36

Hello

I have a game device. I'm trying to map one of it's buttons to keyboard button 'b'. So far, this of course works.

However, the game distinguishes between a "click" (just key down and then immediately up) and a "long press" (key down, wait for 500+ms, key up*).
lmc_send_keys() cannot of course do this, but then I found out about lmc_send_keys(). But I can't make it work.

I've tried these approaches:

Code: Select all

if (direction == 0) and (button == 19) then lmc_send_input(66,0,2) end
if (direction == 1) and (button == 19) then lmc_send_input(66,0,0) end      

Code: Select all

if (button == 19) then
   if (direction == 1) then
      timer19 = ts
   elseif (direction == 0) then
      pressed19 = ts - timer19
      lmc_send_input(66,0,0)
      lmc_sleep(pressed19)
      lmc_send_input(66,0,2)
   end
end                    
Neither of those work. In my head, both should work similarly to pressing and hold down "b" on the keyboard, but they don't. If used in notepad, both ways just send one letter 'b' to the program, not repeating like it does if you hold down a key.

I've also contemplated on using two different keys and just sending the same event, but the other with a pause, but that doesn't work either. Like this:

Code: Select all

if (button == 19) then lmc_send_keys('b') end
if (button == 20) then
      lmc_send_input(66,0,0)
      lmc_sleep(1000)
      lmc_send_input(66,0,2)
end
For some reason that I can't figure out, this does not work either.

ps. The game in question is Star Citizen, can it just somehow be incompatible with lmc_send_input()?

admin
Site Admin
Posts: 595
Joined: 01 Nov 2010, 13:00
Location: Prague, Czech republic
Contact:

Re: Keeping button pressed

Post by admin » 28 Jan 2019, 11:11

I think your scripts are correct.
If you hold down the key at keyboard the repeating hold down action is done by keyboard driver (as you can configure the interval in keyboard settings). However the lmc_send_input is sending single event. So if you need the repetition it can't be done in luamacros unless I add some kind of timers support...
Petr Medek
LUAmacros author

AnnaV
Posts: 8
Joined: 17 Jan 2019, 20:41

Re: Keeping button pressed

Post by AnnaV » 28 Jan 2019, 12:25

Okay, so I'm not completely useless :P I though they were correct. But, for some reason they are not working at all. Any idea if the game in question (Star Citizen) can be incompatible with lmc_send_input()? lmc_send_keys() is working perfectly fine.

AnnaV
Posts: 8
Joined: 17 Jan 2019, 20:41

Re: Keeping button pressed

Post by AnnaV » 28 Jan 2019, 13:37

Yeah, I'm betting my left hand on the culprit being Star Citizen. sadface :(

I base this on evidence that this code:

Code: Select all

clear()
lmc.minimizeToTray = true
lmc.autoReload = true
lmc_device_set_name('NUMPAD', '11788717')
lmc_minimize()

local sc = require 'sc'

map = {};

--First Row
map[144] = sc.PowerToggle;
map[111] = sc.EngineToggle;
map[106] = sc.ShieldsToggle;
map[8] = sc.FlightReady;

--Second Row
map[36] = sc.PowerToWeapons;
map[38] = sc.PowerToEngines;
map[33] = sc.PowerToShields;
map[109] = sc.LightsToggle;

--Third Row
map[37] = sc.PowerReset;
map[12] = sc.ShieldsFront;
map[39] = sc.ShieldsReset;
map[107] = 0;

--4th
map[35] = sc.ShieldsLeft;
map[40] = sc.ShieldsBack;
map[34] = sc.ShieldsRight;

--Two buttons on either side of '00'
map[45] = sc.Agree;
map[46] = sc.Disagree;

--Enter
map[13] = sc.Eject;

button_handler = function(button, direction)
	if (direction == 0) then lmc_send_input(map[button], 0, 0) end
	if (direction == 1) then lmc_send_input(map[button], 0, 2) end
end

lmc_set_handler('NUMPAD',function(button, direction, flags, ts)
  button_handler(button, direction)
  if (direction == 1) then return end  -- ignore down
	if (button == 144) then
      lmc_send_input(144,0,0); -- press NUMLOCK
      lmc_send_input(144,0,2); -- release NUMLOCK
    end
 end)
 
works perfectly and none of the original keypresses come through, only the mapped ones. Everything works on Notepad, explorer, etc.

In Star Citizen though, nothing works - EXCEPT the original keys. If I change the lmc_send_input to lmc_send_keys, it starts to work (but obviously no holding down keys and slightly more complicated code), BUT it also interprets the original keypress regardless of what I have in luaMacros.

Damn that's disappointing. I was hoping to use cheap USB numpads as external controllers in SC, but I guess I need to get a soldering iron and begin to work on button boxes... :/

admin
Site Admin
Posts: 595
Joined: 01 Nov 2010, 13:00
Location: Prague, Czech republic
Contact:

Re: Keeping button pressed

Post by admin » 28 Jan 2019, 14:02

Yes, then it's the game issue. Some games read keyboards "directly", at low level, in the same way as luamacros internally does. Then such programs cannot be hacked with luamacros.
Petr Medek
LUAmacros author

Post Reply