SAP GUI - Shortcodes for developers

Documentation. First post is always kind of manual page, being continuously updated by author. Following posts are discussion about the topic.
Post Reply
J00001
Posts: 1
Joined: 01 Sep 2021, 18:50

SAP GUI - Shortcodes for developers

Post by J00001 » 01 Sep 2021, 19:14

LuaMacros for SAP GUI
  • This is a script I've created and wanted to share with you for using the most used shortcuts for developers for SAP GUI, it should work for all versions of SAP GUI starting from 7.2+
  • This is intended to be used with an external NumPad keyboard, but could be extended to any mapping you see fit.
  • This is not really an advanced macro collection, it will only map some used shortcodes for developers to a more user friendly keystroke.
  • This is intended to be used with logon language EN only.
The current mapping is the following (NumPad):
  • 0: Go Back
  • 1: SE80 - Pretty Print + Save + Activate
  • 2: SE80 - Display all breakpoints
  • 3: SE80 - Go to translations
  • 4: Select text (CTRL+Y)
  • 5: Copy Text (CTRL+C)
  • 6: Paste Text (CTRL+V)
  • 7: Enable debug
  • 8: New Mode
  • 9: Open SE10
  • DOT: Exit (/NEX)
  • ENTER: Execute (F8)
  • BACKSPACE: Where used list
  • PLUS: Open SE80
  • MINUS: Not used
  • MULTIPLY: Open AL11
  • DIVIDE: Open SFP
sap_gui_lua.jpg
sap_gui_lua.jpg (25 KiB) Viewed 852 times
How to extend
  • Functions are named after the keys so any new script should be added within the functions for usability.
  • The key "-" is reserved to go back to another LUA menu script I've redacted that part out so you can use it as you wish.
  • For SAP GUI's extensive shortcuts you need to add some delay for it to work, this may need to be increased in the config section if you see it's not working.
  • You can use the DO_DEBUG function to identify the keys received in case your NUMPAD or device is different.
Installation
  • Download the latest version from the attachment sectionst.
  • Modify line 1 with your device ID.
  • Check and adjust the current mapping to your needs.
Change log
Versions are documented by YYMMDD.

Code: Select all

lmc_device_set_name('KEYPAD', 'E0315A1') -- CHANGE DEVID
delay_time = 150 -- CHANGE DELAY IF COMMAND IS NOT SENT FULLY
lmc.minimizeToTray = true
lmc_minimize()
print("SAP GUI SHORTCODES")
lmc_set_handler('KEYPAD', function(button, direction)
--For each key there is a predifined function that will be called,
--if the key does not respond, you may need to remap it, use the
--DO_DEBUG function to identify what key was pressed, to do so uncomment
--the following line:
--do_debug(button, direction)
--Currently, this will only react to release event of each key.
--More info in https://github.com/me2d13/luamacros/wiki/Basic-Functions
if direction == 0 then
   wrapper_01(button,direction)
end
end)


----------------------------Functions definitions-------------------------------
--Here you can change what certain function of certain key does i.e. the desired
--logic
--------------------------------------------------------------------------------

--DO_0
--KEY: 0
--Current Action: SAP GUI Go Back (F3)
do_0 =  function(button, direction)
     lmc_send_keys('{F3}')
end
--DO_1
--KEY: 1
--Current Action: SAP GUI - SE80 - PP + SAVE + ACTIVATE
do_1 =  function(button, direction)
     lmc_send_keys('+{F1}')
     lmc_sleep(delay_time)
     lmc_send_keys('^s')
     lmc_sleep(delay_time)
     lmc_send_keys('^{F3}')
end
--DO_2
--KEY: 2
--Current Action: SAP GUI - SE80 - Display breakpoints
do_2 =  function(button, direction)
     lmc_send_keys('%s')
     lmc_sleep(delay_time)
     lmc_send_keys('k')
     lmc_sleep(delay_time)
     lmc_send_keys('d')
end
--DO_3
--KEY: 3
--Current Action: SAP GUI - SE80 - OPEN TRANSALATION
do_3 =  function(button, direction)
     lmc_send_keys('%g')
     lmc_sleep(delay_time)
     lmc_send_keys('t')
end
--DO_4
--KEY: 4
--Current Action: SAP GUI Select Text (CTRL+Y)
do_4 =  function(button, direction)
     lmc_send_keys('^y')
end
--DO_5
--KEY: 5
--Current Action: COPY (CTRL+C)
do_5 =  function(button, direction)
     lmc_send_keys('^c')
end
--DO_6
--KEY: 6
--Current Action: PASTE (CTRL+V)
do_6 =  function(button, direction)
     lmc_send_keys('^v')
end
--DO_7
--KEY: 7
--Current Action: SAP GUI - START DEBUG (CTRL+/ , /H , ENTER)
do_7 =  function(button, direction)
     lmc_send_keys('^{NUMDIVIDE}')
     lmc_sleep(delay_time)
     lmc_send_keys('{NUMDIVIDE}H')
     lmc_sleep(delay_time)
     lmc_send_keys('{ENTER}')
end
--DO_8
--KEY: 8
--Current Action: SAP GUI - NEW MODE (CTRL+/ , /ON, ENTER)
do_8 =  function(button, direction)
     lmc_send_keys('^{NUMDIVIDE}')
     lmc_sleep(delay_time)
     lmc_send_keys('{NUMDIVIDE}ON')
     lmc_sleep(delay_time)
     lmc_send_keys('{ENTER}')
end
--DO_9
--KEY: 9
--Current Action: SAP GUI - SE10 (CTRL+/ , /NSE10, ENTER)
do_9 =  function(button, direction)
     lmc_send_keys('^{NUMDIVIDE}')
     lmc_sleep(delay_time)
     lmc_send_keys('{NUMDIVIDE}NSE10')
     lmc_sleep(delay_time)
     lmc_send_keys('{ENTER}')
end
--DO_DIV
--KEY: /
--Current Action: SAP GUI - SFP (CTRL+/ , /NSFP, ENTER)
do_div =  function(button, direction)
     lmc_send_keys('^{NUMDIVIDE}')
     lmc_sleep(delay_time)
     lmc_send_keys('{NUMDIVIDE}NSFP')
     lmc_sleep(delay_time)
     lmc_send_keys('{ENTER}')
end
--DO_MULT
--KEY: *
--Current Action: AL11
do_mult =  function(button, direction)
     lmc_send_keys('^{NUMDIVIDE}')
     lmc_sleep(delay_time)
     lmc_send_keys('{NUMDIVIDE}NAL11')
     lmc_sleep(delay_time)
     lmc_send_keys('{ENTER}')
end
--DO_MIN
--KEY: -
--Current Action: LUA MENU
do_min =  function(button, direction)

end
--DO_ADD
--KEY: +
--Current Action: SAP GUI - SE80
do_add =  function(button, direction)
     lmc_send_keys('^{NUMDIVIDE}')
     lmc_sleep(delay_time)
     lmc_send_keys('{NUMDIVIDE}NSE80')
     lmc_sleep(delay_time)
     lmc_send_keys('{ENTER}')
end
--DO_DOT
--KEY: DOT
--Current Action: SAP GUI - EXIT
do_dot =  function(button, direction)
     lmc_send_keys('^{NUMDIVIDE}')
     lmc_sleep(delay_time)
     lmc_send_keys('{NUMDIVIDE}NEX')
     lmc_sleep(delay_time)
     lmc_send_keys('{ENTER}')
end
--DO_BCKSP
--KEY: BACKSPACE
--Current Action: SAP GUI - SE80 - WHERE USED LIST (CTRL-SHIFT-F3)
do_bcksp =  function(button, direction)
     lmc_send_keys('+^{F3}')
end
--DO_ENTER
--KEY: ENTER
--Current Action: SAP GUI EXECUTE (F8)
do_enter =  function(button, direction)
     lmc_send_keys('{F8}')
end
--DO_DEBUG
--Prints debug information from the LMC_SET_HANDLER event
do_debug = function(button, direction)
  print('Callback for device: button ' .. button .. ', direction '..direction)
end

--WRAPPER_01
--WRAPS THE FUNCTIONALITY FOR ALL KEYS
wrapper_01    = function(button, direction)
     if	button == 96 	then --0
                do_0(button, direction)
	elseif	button == 97 	then -- 1
                do_1(button, direction)
	elseif	button == 98 	then -- 2
                do_2(button, direction)
	elseif	button == 99 	then -- 3
                do_3(button, direction)
	elseif	button == 100	then -- 4
                do_4(button, direction)
	elseif	button == 101	then -- 5
                do_5(button, direction)
	elseif	button == 102	then -- 6
                do_6(button, direction)
	elseif	button == 103	then -- 7
                do_7(button, direction)
	elseif	button == 104	then -- 8
                do_8(button, direction)
	elseif	button == 105	then -- 9
                do_9(button, direction)
	elseif	button == 106	then -- *
                do_mult(button, direction)
	elseif	button == 107	then -- +
                do_add(button, direction)
	elseif	button == 109	then -- -
                do_min(button, direction)
	elseif	button == 110	then -- .
                do_dot(button, direction)
	elseif	button == 111	then -- /
                do_div(button, direction)
	elseif	button == 8	then -- BCKSPC
                do_bcksp(button, direction)
	elseif	button == 13	then -- ENTER
                do_enter(button, direction)
     end
end
Attachments
SAP_GUI_210901.zip
(1.48 KiB) Downloaded 67 times

Post Reply