Mapp Numpad key to act as "Shift" key

Announcements, questions
Post Reply
Ronin_pH
Posts: 4
Joined: 14 Dec 2017, 11:37

Mapp Numpad key to act as "Shift" key

Post by Ronin_pH » 14 Dec 2017, 11:46

Hello!

Let me start of with thanking for an excellent program, as it solves many peoples problems, and makes working easier for even more :D

I was wondering if there is a way to map the "Shift" key to a key on my extra USB numpad. I was thinking that I want the "+" key to function the same way as the "Shift" key works on the normal keyboard. The work I do involves a lot of scrolling, both up and down, as well as left to right, so as it is right now, I have to move my hand from my numpad, up to the normal keyboard, when I want to scroll horisontally, as well as when I want to select multiple files/objects/etc.

I have tried lmc_send_keys('+'), but it does't work with just this modifier, it seems.

I hope someone has a solution, that I just might have overlooked! :)

Thank you!
Best Regards,
/Ronin_pH

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

Re: Mapp Numpad key to act as "Shift" key

Post by admin » 15 Dec 2017, 09:22

You could try to use lmc_send_input to "virtually" press shift on + down and release on + up. But I'm not sure if it affects other regular keys (why holding shift down "virtually" from macro).
Also I think holding regular (+) key down will result to repeated down events for that key - this is windows feature for non-modifier keys.
Try and see...
Petr Medek
LUAmacros author

Ronin_pH
Posts: 4
Joined: 14 Dec 2017, 11:37

Re: Mapp Numpad key to act as "Shift" key

Post by Ronin_pH » 15 Dec 2017, 15:30

Hello!

The code I have so far looks like this:

Code: Select all

-- assign logical name to macro keyboard
lmc_assign_keyboard('MACROS');

-- list all devices
lmc_print_devices();

lmc_set_handler('MACROS',function(button, direction)
	-- if (direction == 1) then return end -- ignore keydown

-- Mapping buttons that are not affected by Num Lock
	if      (button == 8) then lmc_send_keys('{BACKSPACE}')   -- Numpad Key "Backspace" => "Backspace"
        elseif  (button == 9) then lmc_send_keys('{TAB}')         -- Numpad Key "Tab" => "Tab"
        elseif  (button == 13) then lmc_send_keys('{ENTER}')      -- Numpad Key "Enter" => "Enter"
        elseif  (button == 107) then lmc_send_keys('+')           -- Numpad Key "+" => "Shift"?
(There is of course more code, as I'm mapping "Cut", "Copy", "Paste" etc to my numpad, but wanted to spare you the long scroll)

I have commented out the part of the code that causes "ignore keydown", as this stopped me being able to use the "UP", "DOWN", "LEFT", "RIGHT" etc by just holding the key down.

So naturally I thought, since I now can just hold those keys down, and they repeat that command, maybe putting the shift-modifier on the "+"-key will work now, but it didn't.

Is there any {SHIFT} function that one could use? (Like the {BACKSPACE}, for example).

Thank you for your help!
Best Regards,
/Ronin_pH

Ronin_pH
Posts: 4
Joined: 14 Dec 2017, 11:37

Re: Mapp Numpad key to act as "Shift" key

Post by Ronin_pH » 15 Dec 2017, 15:48

Hello again!

I am now noticing that commenting out the

Code: Select all

if (direction == 1) then return end -- ignore keydown
bit, causes "Copy", "Backspace", and other such commands that I have mapped to happen twice: once on keydown, and once on keyup.

Should I maybe group my commands by direction? As in, first have an if-statement for the direction "key is pressed down", and what commands I want to execute in that state, and then another if-statement for the direction "key is not pressed anymore"?

Thank you for your time and help!
Best Regards,
/Ronin_pH

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

Re: Mapp Numpad key to act as "Shift" key

Post by admin » 18 Dec 2017, 09:19

I told you to use lms_send_input, not lmc_send_keys. With lmc_send_input you can send just shift and you can send only down or up event.
Some info here: http://www.hidmacros.eu/forum/viewtopic.php?f=12&t=475
Petr Medek
LUAmacros author

Ronin_pH
Posts: 4
Joined: 14 Dec 2017, 11:37

Re: Mapp Numpad key to act as "Shift" key

Post by Ronin_pH » 19 Dec 2017, 11:06

I told you to use lms_send_input, not lmc_send_keys.
Yes, I know you said that, that's why I asked the following of you:
Should I maybe group my commands by direction? As in, first have an if-statement for the direction "key is pressed down", and what commands I want to execute in that state, and then another if-statement for the direction "key is not pressed anymore"?
I showed the code I have right now because it works in all aspects, except for making Shift work. And can't see how to get a key press to trigger both "Shift On" and "Shift off" in one key press. Hence the question: should I make some code for when I press the keys down, and start triggering key events there, and then have them to stopp triggering in another piece of code where I release the key?
Best Regards,
/Ronin_pH

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

Re: Mapp Numpad key to act as "Shift" key

Post by admin » 20 Dec 2017, 10:03

With lmc_send_input you can separate sending press or release only. With lmc_send_keys you can't - it always sends press & release.
If you want + key to send shift down on press and shift up on release then you (of course) need to check direction value in the handler and do appropriate lmc_send_input call.
But I still doubt if this "virtual shift down" will work as reguler (e.g. multiselect with mouse). You'll see...
Petr Medek
LUAmacros author

Roel
Posts: 1
Joined: 07 Apr 2018, 20:33

Re: Mapp Numpad key to act as "Shift" key

Post by Roel » 07 Apr 2018, 20:53

Ronin_pH wrote:
15 Dec 2017, 15:48
Hello again!

I am now noticing that commenting out the

Code: Select all

if (direction == 1) then return end -- ignore keydown
bit, causes "Copy", "Backspace", and other such commands that I have mapped to happen twice: once on keydown, and once on keyup.

Should I maybe group my commands by direction? As in, first have an if-statement for the direction "key is pressed down", and what commands I want to execute in that state, and then another if-statement for the direction "key is not pressed anymore"?

Thank you for your time and help!
I think that this is the best way to do it. This is how I did it for myself:

Code: Select all

--when keyDown
  if (direction == 1) then
    if     (button == 16) then lmc_send_input(16, 0, 0)                --press Shift key
    elseif (button == string.byte('A')) then lmc_send_input(65, 0, 0)  --press "a" key
    else return end
  end

--when keyUp
  if (direction == 1) then return end  --now ignore keyDown

    if     (button == 16) then lmc_send_input(16, 0, 2)  --release Shift key
    elseif (button == 65) then lmc_send_input(65, 0, 2)  --release "a" key

    elseif (button == 55) then lmc_send_input(55, 0, 0)  --normal keys. Just do sth once(when keyUp)

    else print('Not yet assigned: ' .. button)
    end  
If anybody has any better idea, please tell me... It would help!

Post Reply