Remap laptop internal keys

How can be this controlled in that simulator? Can HIDmacros be used with this application?
Post Reply
yxz11
Posts: 5
Joined: 26 Aug 2021, 00:34

Remap laptop internal keys

Post by yxz11 » 26 Aug 2021, 01:01

Hello there,

I need some help remapping laptop keys.

Here is my scenario: I have a Microsoft Surface with type cover, I want to keep F1-F8 intact and swap F9 with "Home", F10 with "End", F11 with "PgUp" and F12 with "PgDn". Follow quistart.lua I got following code, however, it has two issues:

1. I cannot use any other key, how can I bypass luamacros for other keys?
2. It seems following code doesn't works for F9-F12, I got some strange results, it seems anther key is sent afterwards.

Your help is greatly appreciated.

Code: Select all

lmc_device_set_name('SurfaceCover', "ID_09C0") -- substitute the ID you have found here
lmc_set_handler('SurfaceCover',function(button, direction)
  if (direction == 1) then return end  -- ignore down;
  if     (button == 120) then lmc_send_keys('{HOME}')
  elseif (button == 121) then lmc_send_keys('{END}')
  elseif (button == 122) then lmc_send_keys('{PGUP}')
  elseif (button == 123) then lmc_send_keys('{PGDN}')
  elseif (button == 36) then lmc_send_keys('{F9}')
  elseif (button == 35) then lmc_send_keys('{F10}')
  elseif (button == 33) then lmc_send_keys('{F11}')
  elseif (button == 34) then lmc_send_keys('{F12}')  
  else print('Not yet assigned: ' .. button)
  end
end)

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

Re: Remap laptop internal keys

Post by admin » 30 Aug 2021, 08:03

You can call lmc_set_handler to bind only one key, not whole keyboard. Check wiki at github.
Petr Medek
LUAmacros author

yxz11
Posts: 5
Joined: 26 Aug 2021, 00:34

Re: Remap laptop internal keys

Post by yxz11 » 07 Sep 2021, 14:49

Thanks, this works.

Code: Select all

lmc_device_set_name('SurfaceCover', "ID_09C0")
lmc_set_handler('SurfaceCover',120,1,function()
  lmc_send_keys('{HOME}')
end)
One more question, how do I send the "CTRL"? What I'm trying to do is to remap the "Context Menu" key to "ctrl" key. What do I need to put in where "????" is:

Code: Select all

lmc_set_handler('SurfaceCover',93,1,function()
  lmc_send_keys('{????}')
end)

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

Re: Remap laptop internal keys

Post by admin » 08 Sep 2021, 07:46

Use lmc_send_input - one call for ctrl down, another for ctrl up
Petr Medek
LUAmacros author

yxz11
Posts: 5
Joined: 26 Aug 2021, 00:34

Re: Remap laptop internal keys

Post by yxz11 » 15 Oct 2021, 02:45

Just want to post the working solution I have now, hope this is useful. And thanks again for the great utility:

Code: Select all

lmc.minimizeToTray = true
lmc_minimize()

-- find out the device id for internal keyboard
--lmc_print_devices()   -- get the ID of the second keyboard from the stack that this line creates
lmc_device_set_name('SurfaceCover', "ID_09C0") -- substitute the ID you have found here

-- swap F9 and HOME key
lmc_set_handler('SurfaceCover',120,1,function()
  lmc_send_keys('{HOME}')
end)
lmc_set_handler('SurfaceCover',36,1,function()
  lmc_send_keys('{F9}')
end)
-- http://www.hidmacros.eu/forum/viewtopic.php?t=528
-- Change menu key to ctrl
lmc_set_handler('SurfaceCover',93,1,function()
  lmc_send_input(17, 0, 0) -- press
end)
lmc_set_handler('SurfaceCover',93,0,function()
  lmc_send_input(17, 0, 2) -- release
end)



yxz11
Posts: 5
Joined: 26 Aug 2021, 00:34

Re: Remap laptop internal keys

Post by yxz11 » 30 Nov 2021, 01:24

Now I have two problems:

1. The macro worked for a while, then stopped working, I have to restart it to make it work again.

2. After mapping the "menu" key to ctrl using following, it sends ctrl but also sends "menu"?

Any idea what I did wrong?

lmc_set_handler('SurfaceCover',93,1,function()
lmc_send_input(17, 0, 0) -- press
end)
lmc_set_handler('SurfaceCover',93,0,function()
lmc_send_input(17, 0, 2) -- release
end)

Post Reply