Handle Ctrl+Key with Keydown event

Posted by: newbee on 8 September 2017, 2:44 pm EST

  • Posted 8 September 2017, 2:44 pm EST

    Hi,


     How do I determine if the user has pressed some combination like Ctrl+1 for example?


    In <FONT size=2>AxFPSpreadADO.</FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>_DSpreadEvents_KeyDownEvent</FONT></FONT><FONT size=2> e, I see <FONT size=2>keyCode, but nothing that tells me wether a control or alt or shift key was pressed or not.</FONT></FONT>


    <FONT size=2><FONT size=2> </FONT></FONT><FONT size=2><FONT size=2>Thanks.

    </FONT></FONT>
  • Replied 8 September 2017, 2:44 pm EST

    Hello,

    The KeyEventArgs object e, in the event has a Modifiers property that lets you know if a control, shift or alt key was pressed. Here is an example code which lets you know that Ctrl+A was pressed:







    pre { font-family: "Liberation Serif"; }p { margin-bottom: 0.21cm; }

    void fpSpread1_KeyDown(object sender,
    KeyEventArgs e)

    {

         if (e.Modifiers == Keys.Control && e.KeyCode == Keys.A)

           MessageBox.Show("Key down event, keys pressed: Ctrl+A");

    }<font size="2"></font>

    <font size="2">Please let me know if this is what you needed or I am missing something.</font>

    <font size="2">Thanks,</font><font size="2"></font>

    <font size="2">Manpreet Kaur </font>


     

    pre { font-family: "Liberation Serif"; }p { margin-bottom: 0

  • Replied 8 September 2017, 2:44 pm EST

    I am using Spread COM version 8.


     I don't see a property called "Modifiers" for e.


    I do see something called "shift" but I am not sure how to use it.


     Thanks.

  • Replied 8 September 2017, 2:44 pm EST

    Can someone please reply to this?


    I need it rather quickly.


    Thanks.

  • Replied 8 September 2017, 2:44 pm EST

    Hello,

    You can catch the KeyDown event for Spread and get to know whether the Ctrl key is pressed using the following code:

    Private Sub AxfpSpread1_KeyDownEvent(ByVal sender As Object, ByVal e As AxFPSpreadADO._DSpreadEvents_KeyDownEvent) Handles AxfpSpread1.KeyDownEvent

            If e.shift = 2 Then

                MsgBox("ctrl key pressed")

            End If

    End Sub

     

    Thanks,

     

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels