button combination

Announcements, questions
Post Reply
Jack
Posts: 3
Joined: 08 Nov 2017, 22:48

button combination

Post by Jack » 08 Nov 2017, 23:12

Hello,

I am writing a script for my keyboard, and I am out off keys now.
I only need a few more, so using a extra keyboard is to mutch.
is there a possibility to hit a key combination to send a input?

if (button == 81) then lmc_send_input(49, 0, 0) -- press 1
lmc_send_input(49, 0, 2) -- release 1
elseif (button == 87) then lmc_send_input(50, 0, 0) -- press 2
lmc_send_input(50, 0, 0) -- release 2

Is there a way to push button 81 and 87, then send a input (or any other combi ofcourse)
------------------------------------------------------------------------------------------------------------
elseif (button == ???81 and 87???) then lmc_send_input(51, 0, 0) -- press 3
lmc_send_input(51, 0, 0) -- release 3
------------------------------------------------------------------------------------------------------------

Thank a lot,
Jack

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

Re: button combination

Post by admin » 09 Nov 2017, 09:29

This should be easy to implement using variable, shouldn't?
81 down -> set some variable e.g. shift = 1
81 up -> set some variable e.g. shift = 0
87: if (shift = 1) do action1 else do action2
Petr Medek
HIDmacros author

Jack
Posts: 3
Joined: 08 Nov 2017, 22:48

Re: button combination

Post by Jack » 09 Nov 2017, 11:21

Hi thanks for the reply.

I found the "use of variable" topic.
I change a bit and I tried it, but it is not working like think it should be , but maybe I make a mistake.

Code: Select all

clear();
lmc_device_set_name('RIGHT', '2417B41')
--lmc.minimizeToTray = true
shift = true

alt = function()
  if(shift) then
   lmc_send_keys('Special')
  else
   lmc_send_keys('Normal')
  end
end


shift = function()
 if (shift) then
  shift = false
 else
  shift = true
 end

 if(shift) then
  print('shift is on')
 else
  print('shift is off')
 end


end

lmc_set_handler('RIGHT',16,0,shift)
lmc_set_handler('RIGHT',18,0,alt)       
when I start the script, it starts with shift on. but I want it to start with off. probably I just make a mistake.
when shift off normal caracters
when shift on, special caracters

I tried to find out this
This should be easy to implement using variable, shouldn't?
81 down -> set some variable e.g. shift = 1
81 up -> set some variable e.g. shift = 0
87: if (shift = 1) do action1 else do action2
but could not find out how the script for this should look like.
do you have a example script ?

Thanks,
Jack

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

Re: button combination

Post by admin » 10 Nov 2017, 09:31

When using lmc_set_handler for specific key (not whole keyboard) it has parameters:
  • Device name
  • Button number
  • Direction 1 = down, 0 = up
  • handler
So you should have 2 handler functions for "shift" key - one for key press which sets your shift = true and second for relese which sets shift = false
Petr Medek
HIDmacros author

Jack
Posts: 3
Joined: 08 Nov 2017, 22:48

Re: button combination

Post by Jack » 10 Nov 2017, 11:47

Hi,

This is all new for me.
I try to find all the information on the internet and read it to learn this.

back to the button 81 an 87 Question,
This is what I made with the best understanding of your tips.

Code: Select all

clear();
lmc_device_set_name('RIGHT', '2417B41')
--lmc.minimizeToTray = true

W = function()
  if (Qdown) then
   lmc_send_input(51, 0, 0)
   lmc_send_input(51, 0, 2)
   else
   lmc_send_input(50, 0, 0)
   lmc_send_input(50, 0, 2)
  end
end

Qdown = function()
   Qdown = true
end

Qup = function()
   Qdown = false
end

lmc_set_handler('RIGHT',81,0,Qup)
lmc_set_handler('RIGHT',81,1,Qdown)
lmc_set_handler('RIGHT',87,0,W)  

When I start the script first it dont work the corect way, when I hit the W key it sends a 3.
after I hit the Q key ones, the W key sends 2.
How to fix this??
When I hold down Q and hit W it send 3.... so that works.

What I can''t find out is how to send a 1 when I hit the Q button without also sending a 1 when I use Q in the QW combination.
How to fix this??


Thanks a lot for the tips.
Jack

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

Re: button combination

Post by admin » 13 Nov 2017, 09:09

I think you need to go through some Lua tutorial if you want to use LuaMacros.
Your script has a few problems
- you're not initializing Qdown
- in global scope Qdown is function (not boolean) so your if doesn't work as you would expect
- setting Qdown in handler probably creates just local boolean variable (not a good idea to name handler function and boolean flag with the same name)

Without checking in LuaMacros I would try something like:

Code: Select all

clear();
lmc_device_set_name('RIGHT', '2417B41')
--lmc.minimizeToTray = true

QdownFlag = false

W = function()
  if (QdownFlag) then
   lmc_send_input(51, 0, 0)
   lmc_send_input(51, 0, 2)
   else
   lmc_send_input(50, 0, 0)
   lmc_send_input(50, 0, 2)
  end
end

QdownHandler = function()
   QdownFlag = true
end

QupHandler = function()
   QdownFlag = false
end

lmc_set_handler('RIGHT',81,0,QupHandler)
lmc_set_handler('RIGHT',81,1,QdownHandler)
lmc_set_handler('RIGHT',87,0,W)
Petr Medek
HIDmacros author

cristiano_pruneri
Posts: 12
Joined: 19 Jul 2013, 12:43

Re: button combination

Post by cristiano_pruneri » 22 Nov 2017, 11:53

If I may suggest, look at from Macrorecorder, by Pavlov Andrew

https://github.com/mrsimb/macrorecorder

He uses a brilliant idea (so brilliant it took me a while to fully grasp it ) - he associates to each key an object that track its status, globally indexed so that it can be accessed by other key handlers.

He uses it to see if the modifiers are down, but it gives the status of any key, so the possibility is there to use any arbitrary key as modifier.

Beware, however, of hardware limitations in that case...

The modifiers are different from normal keys in that they do not send the "down" code while they are kept pressed, as all other keys do.

As a result, you usually cannot have more than two "normal" keys pressed at the same time...

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests