kmcdowellLB
Guest
|
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? |
|
Andrei Smolin
Add-in Express team
Posts: 18821
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.
Andrei Smolin
Add-in Express Team Leader |
|
kmcdowellLB
Guest
|
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. |
|
Andrei Smolin
Add-in Express team
Posts: 18821
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.
Andrei Smolin
Add-in Express Team Leader |
|
kmcdowellLB
Guest
|
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! |
|
Andrei Smolin
Add-in Express team
Posts: 18821
Joined: 2006-05-11
|
|