Customize your keys in SAS Enterprise Guide with AutoHotkey

This post was kindly contributed by The SAS Dummy - go there to comment and to read the full post.

DMS keysSAS power users (and actually, power users of any application) like to customize their environment for maximum productivity. Long-time SAS users remember the KEYS window in SAS display manager, which allows you to assign SAS commands to “hot keys” in your SAS session. These users will invest many hours to come up with the perfect keyboard mappings to suit the type of work that they do.

When using SAS Enterprise Guide, these power users often lament the lack of a similar KEYS window. But these people needn’t suffer with the default keys — a popular tool named AutoHotkey can fill the gap for this and for any other Windows application. I’ve recommended it to many SAS users over the years, and I’ve heard positive feedback from those who have adopted it. AutoHotkey is free, and it’s lightweight and portable; even users with “locked-down” systems can usually make use of it.

AutoHotkey provides its own powerful scripting language, which allows you define new behaviors for any key combination that you want to repurpose. When you activate these scripts, AutoHotkey gets first crack at processing your keypress, so you can redirect the built-in key mappings for any Windows application. I’ll share two examples of different types of scripts that users have found helpful.

“Unmap” a key that you don’t like

In SAS Enterprise Guide, F3 and F8 are both mapped to “Run program”. A newer user found the F8 mapping confusing because she had a habit of using that key for something else, and so became quite annoyed when she kept accidentally running her process before she was ready.

The following AutoHotkey script “eats” the F8 keypress. The logic first checks to see if the running process is SAS Enterprise Guide (seguide.exe), and if so, it simply stops processing the action, effectively vetoing the F8 action.

F8::
WinGet, Active_ID, ID, A
WinGet, Active_Process, ProcessName, ahk_id %Active_ID%
if ( Active_Process ="seguide.exe" ) {
  ;eat the keystroke
} 

Map a single key to an action that requires multiple keys or clicks

I recently shared a tip to close all open data sets in SAS Enterprise Guide. It’s a feature on the Tools menu that launches a special window, and some readers wished for a single key mapping to get the job done. Using AutoHotkey, you can map a series of clicks/keystrokes to a single key.

The following script will select the menu item, activate the “View Open Data Sets” window, and then select Close All.

F12::
WinGet, Active_ID, ID, A
WinGet, Active_Process, ProcessName, ahk_id %Active_ID%
if ( Active_Process ="seguide.exe" ) 
{
  Sleep, 100
  Send {Alt Down}{Alt Up}{t}
  Sleep, 100  
  Send, {v}
  WinActivate, View Open Data Sets ahk_class WindowsForms10.Window.8.app.0.143a722_r12_ad1
  Send, {Tab}
  Sleep, 100  
  Send, {Space}
  Sleep, 500  
  Send, {Esc}
}

You’ll see that one of the script commands activates the “View Open Data Sets” window. The window “class” is referenced, and the class name is hardly intuitive. AutoHotkey includes a “Window spy” utility called “Active Window Info” that can help you to find the exact name of the window you need to activate.

Window Spy

AutoHotkey can direct mouse movements and clicks, but those directives might not be reliable in different Windows configurations. In my scripts, I rely on simulated keyboard commands. This script activates the top-level menu with Alt+”t” (for Tools), then “v” (for the “View Open Data Sets” window), then TAB to the “Close All” button, space bar to press the button, then Escape to close the window. Each action takes some time to take effect, so “Sleep” commands are inserted (with times in milliseconds) to allow the actions to complete.

Every action in SAS Enterprise Guide is accessible by the keyboard (even if several keystrokes are required). If you want to see all of the already-defined keyboard mappings, search the SAS Enterprise Guide help for “keyboard shortcuts.”

Key help

Automate more with AutoHotkey

In this article, I’ve only just scratched the surface of how you can customize keys and automate actions in SAS Enterprise Guide. Some of our users have asked us to build in the ability to customize key actions within the application. While that might be a good enhancement within the boundaries of your SAS applications, a tool like AutoHotkey can help you to automate your common tasks within SAS and across other applications that you use. The scripting language presents a bit of a learning curve, but the online help is excellent. And there is a large community of AutoHotkey users who have published hundreds of useful examples.

Have you used AutoHotkey to automate any SAS tasks? If so, please share your tips here in the comments or within the SAS Enterprise Guide community.

The post Customize your keys in SAS Enterprise Guide with AutoHotkey appeared first on The SAS Dummy.

This post was kindly contributed by The SAS Dummy - go there to comment and to read the full post.