none
How to capture control+ z event for my excel dna application? RRS feed

  • Question

  • I am working on an excel-dna plugin application.

    I want to write my logic on undo and redo. For that i want to capture the control and z key press event.

    Can anyone please guide me how to capture the event of key press?

    • Moved by CoolDadTx Tuesday, August 6, 2019 3:34 PM Office related
    Tuesday, August 6, 2019 9:51 AM

All replies

  • Hi,

    With using Windows API (User32.dll), you can capture key press.

    This is a sample.

    [VBA code]
    Option Explicit
    
    ' --- Windows API
    Private Declare Function GetAsyncKeyState _
            Lib "User32.dll" (ByVal vKey As Long) As Long
    
    Private Sub btn_Start_Click()
        ' --- Loop until [Esc] pressed
        Do
            ' --- [Esc]
            If (GetAsyncKeyState(vbKeyEscape)) Then
                Range("A3").Value = ""
                Exit Do    ' -- Exit Do-Loop
            End If
            ' --- [Ctrl]+[Z]
            If (GetAsyncKeyState(vbKeyControl) And _
                GetAsyncKeyState(vbKeyZ)) Then
                Range("A3").Value = "Ctrl + Z"
            End If
            ' --- [Ctrl]+[Y]
            If (GetAsyncKeyState(vbKeyControl) And _
                GetAsyncKeyState(vbKeyY)) Then
                Range("A3").Value = "Ctrl + Y"
            End If
        Loop
    End Sub
    

    Regards,

    Ashidacchi -- https://ssl01.rocketnet.jp/hokusosha.com/default.html

    Wednesday, August 7, 2019 2:06 AM