0

I'm using a program (Comsol) that computes a formula entered into one cell in a table, and places the result into another cell. The first cell is editable, and I can copy from it to clipboard with Ctrl+C, but the second cell is non-editable and Ctrl+C does nothing. Which means that I either have to re-implement the computation myself, or type the digits of the numerical answer manually.

I used the Window Spy utility from AutoHotkey (from context menu on an AHK running script in the system tray) to see that the control implementing the table is a ListView control (called SysListView3217 or SysListView3218 or similar), so is a standard Windows control, just the same as used in Windows Explorer to display files and folders. This is not surprising because Comsol GUI is obviously built with SWT, which uses native Windows controls.

This is half-way there. What would be an elegant way to use AutoHotkey to grab the text from the SysListView?

1 Answer 1

1

Collecting examples from several sources (especially this one, and also this), here is a script I came up with:

#SingleInstance Force
#NoEnv

#c::
MouseGetPos, , , , ListView_hwnd, 2     ;2 means return HWND
ControlGet, selected_row_text, List, Selected, , ahk_id %ListView_hwnd%
Gui, +ToolWindow +AlwaysOnTop -Caption
Gui, Add, Edit, unused_variable x11 y15 w950 h66, %selected_row_text%
Gui, Add, Button, x62 y84 w140 h30 +Center, Close
Gui, Show, ,
return

ButtonClose:
Gui, Destroy
return

Place this into an AHK file to run. Select a row in the SysListView control, then press Win+C, and you should get a window like this (familiar Windows Explorer as an example):

Script action shot

The text can be then copied to clipboard from that window with the usual Ctrl+C.

(The MouseGetPos line picks the SysListView currently under the mouse cursor, and the line after that gets the text of the selected table row. All the other lines are there to display the window with a textbox containing the text.)

1
  • Note that if we remove the word Selected (i.e. the context will become List, , , ahk_id %ListView_hwnd%), then all of the items are copied. This is for those lists where only a single row may be selected at a time (like the list control in Windows Update history). May 15, 2017 at 8:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .