Copy (to clipboard) from table (list) in a program on Windows

0

1

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?

Evgeni Sergeev

Posted 2014-09-22T04:05:05.460

Reputation: 1 704

Answers

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.)

Evgeni Sergeev

Posted 2014-09-22T04:05:05.460

Reputation: 1 704

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). – Evgeni Sergeev – 2017-05-15T08:00:52.260