Forum Discussion

jolee_stewart's avatar
11 years ago

Number Pad Enter

Hi,

I have a system that requires that you use specific Enter keys to be able to progress as it is really old and finicky.

Using Keys("[Enter]") uses the normal Enter on the main part of the keyboard.

I want to be able to specify the Enter key on the number pad.

How do I do this?



Thanks

4 Replies

  • TestComplete's Keys method cannot simulate the numpad Enter. A possible solution is to write an utility that uses the Windows API SendInput function to simulate the VK_RETURN key code with the KEYEVENTF_EXTENDEDKEY flag.



    Here's a C# example:

    http://inputsimulator.codeplex.com/discussions/277342



    To use this code from TestComplete:


    1. make it a static method,


    2. compile it into an assembly,


    3. add the assembly to Tools > Current Project Properties > CLR Bridge.


    Then you can call the method like this:



    // JScript

    dotNET.your_namespace.class.method();

  • AlexKaras's avatar
    AlexKaras
    Icon for Champion Level 1 rankChampion Level 1
    The followers of the old school and those who like native solutions :) may adopt the following ages old code (which illustrates original Helen's suggestion):


    '-------------------------------------------------------------------------------


    Sub SetCapsLock(AState)

    'Subroutine toggles the CAPS LOCK light.

    'It takes a Boolean value that indicates whether the light should be turned off (FALSE) or on (TRUE).



    ' An application can simulate a press of the PRINTSCRN key in order to obtain a screen snapshot

    ' and save it to the clipboard. To do this, call keybd_event with the bVk parameter set to VK_SNAPSHOT.

    ' Windows NT: The keybd_event function can toggle the NUM LOCK, CAPS LOCK, and SCROLL LOCK keys.

    ' Windows 95: The keybd_event function can toggle only the CAPS LOCK and SCROLL LOCK keys.

    ' It cannot toggle the NUM LOCK key.



        If (AState And Not ((Win32API.GetKeyState(VK_CAPITAL) And 1) > 0)) Or _

                (Not AState And ((Win32API.GetKeyState(VK_CAPITAL) And 1) > 0)) Then

            ' Simulate a key press

            Call Win32API.keybd_event(VK_CAPITAL, VK_CAPITAL, KEYEVENTF_EXTENDEDKEY, 0)

            ' Simulate a key release

            Call Win32API.keybd_event(VK_CAPITAL, VK_CAPITAL, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0)

        End If

    End Sub

    '-----------------------------------------------------------------------------





    '-------------------------------------------------------------------------------

    ' The code simulates the Windows + R shortcut

    Sub PressWindowsR

        Call Win32API.keybd_event(VK_LWIN, 0, 0, 0)

        Call Win32API.keybd_event(82, 0, 0, 0)

        Call Win32API.keybd_event(82, 0, KEYEVENTF_KEYUP, 0)

        Call Win32API.keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0)

    End Sub

    '-------------------------------------------------------------------------------


  • Old school is great! :) I was looking for a way to hook up SendInput and forgot about keybd_event. Thanks, Alexei!



    So this should do the trick:



    // Press numpad Enter - JScript

    var SC_RETURN = Win32API.MapVirtualKey(Win32API.VK_RETURN, 0 /* MAPVK_VK_TO_VSC */);

    Win32API.keybd_event(Win32API.VK_RETURN, SC_RETURN, Win32API.KEYEVENTF_EXTENDEDKEY, 0);

    Win32API.keybd_event(Win32API.VK_RETURN, SC_RETURN, Win32API.KEYEVENTF_EXTENDEDKEY | Win32API.KEYEVENTF_KEYUP, 0);