Is ther a way to get a KeyUp Event from Excel

Add-in Express™ Support Service
That's what is more important than anything else

Is ther a way to get a KeyUp Event from Excel
 
kmcdowellLB




Posts: 7
Joined: 2020-02-28
Keyboard shortcuts and KeyDown events are present in the AddinExpressModule object. But what I really need is a KeyUp event. I need to be able to detect when a user has stopped zooming through a spreadsheet by holding down an arrow key. Any ideas?
Posted 28 Feb, 2020 16:18:39 Top
Andrei Smolin


Add-in Express team


Posts: 17178
Joined: 2006-05-11
Hello,

How can I use an arrow key to zoom the sheet?

There's a simple way to get the current zoom using the Excel Object Model only. There's the CommandBars.Update event. Add-in Express maps it to the CommandBarsUpdate event of the Excel Events component (ADXExcelAppEvents). That event is the heartbeat of the Excel application: all kind of changes raise it. You are supposed to get the current zoom and react to it.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 02 Mar, 2020 04:22:09 Top
kmcdowellLB




Posts: 7
Joined: 2020-02-28
Hi Andrei,

Sorry I caused confusion with my use of the word "Zoom". Allow to to explain a bit more. I have a WorksheetEvents object that traps the SelectionChange event for the underlying worksheet. The idea here is that as the user moves the excel selection cursor around the sheet, I am picking up data from the cell and doing some processing that takes a 1/2 second or so. The performance is good enough when selecting cells, but it becomes very noticeable when someone is holding down an arrow key to move quickly through cells.

For my purposes, I really only need to process the cell that they land on; My idea was to ignore processing in the selection change event while an arrow key is held down. But then, once the arrow key is lifted, I would need to trigger the selection change event processing on the finally selected cell. This is why I was hoping to find some sort of OnKeyUp event.
Posted 02 Mar, 2020 08:52:44 Top
Andrei Smolin


Add-in Express team


Posts: 17178
Joined: 2006-05-11
Hello,

You need to have a timer that fires its event on the main thread. I recommend using a System.Windows.Forms.Timer. Experiment with Interval property: set it e.g. to 200-500 ms.

In the event handler of the SelectionChange event, you check the timer: if it isn't started, you start it; if it is started, you stop and restart it. When the timer fires its event, you get the selection and process it.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 02 Mar, 2020 09:13:49 Top
kmcdowellLB




Posts: 7
Joined: 2020-02-28
Hi again,

This is a very clever idea. This worked out well for me. I just also needed to be careful to check if Excel is in Edit Mode, as this opens an opportunity for a user to do a fast double click to enter a cell.

Thank you for the suggestion!
Posted 02 Mar, 2020 16:45:16 Top
Andrei Smolin


Add-in Express team


Posts: 17178
Joined: 2006-05-11
Hello,

kmcdowellLB writes:
I just also needed to be careful to check if Excel is in Edit Mode, as this opens an opportunity for a user to do a fast double click to enter a cell.


Check How to check programmatically if the user is editing an Excel cell. Pay attention to comments!

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 03 Mar, 2020 03:35:01 Top