Purpose
You want to embed your own Windows Forms applications in the SAP screen and react to keystrokes there, especially those that are normally handled by the SAP GUI.
 
In this example we show how you can allow the user to switch between individual inputfields using the Tab key, just like on the SAP screen.
 

Solution
First, create a Windows Forms application in the usual way. Please specify the .NET framework version 4.x as target framework here. Then define the tab index in the application, i.e. the order in which the elements can be selected with the tab key.

You can test this straight away, but the Tab key does not work in the usual way if you embed the application in the SAP GUI, because the SAP GUI intercepts these commands and does not forward them directly to the control.

However, we can insert event handlers for all elements used and then check whether the Tab key has been pressed. If this is the case, we call the SelectNextControl() function, which sets the focus to the next element. This function also has a direction parameter that you can set to backwards or false if the user has pressed Shift + Tab.

Private Sub TextBox1_KeyDown(sender As Object, e As KeyEventArgs) _
        Handles TextBox1.KeyDown

        If e.KeyCode = Keys.Tab Then

            e.Handled = True
            e.SuppressKeyPress = True
            SelectNextControl(sender, Not e.Shift, True, True, True)
        End If

    End Sub

Unfortunately, Windows plays a system sound at this point. We can suppress this by suppressing further event handling with the following code:

e.Handled = True
e.SuppressKeyPress = True


After that, you just need to compile the project as a class library instead of an executable .EXE file, and you can embed the application using a GuiXT command.

Tip:
You can also add any other conceivable event handlers for elements, and thus react to clicks or mouseovers, for example.

Script for creating an order:
In this example, we want to create an order directly from the embedded control. Therefore, when you click on the corresponding button, several GuiXT variables are filled and an InputScript is started:

 Private Sub Button2_Click(sender As Object, e As EventArgs) _
        Handles Button2.Click

        fill_data()
        myguixt.Input("U[ORDERTYPE]:RE;OK:/0,process=create_simple_order.txt")

    End Sub

    Public Sub fill_data()

        myguixt.SetVariable("customerno", TextBox1.Text)
        myguixt.SetVariable("matno", TextBox2.Text)
        myguixt.SetVariable("quant", TextBox3.Text)
        myguixt.SetVariable("orderno", TextBox4.Text)

    End Sub

GuiXT Script:

del (0,0) (100,100)
Control (0,0) (11.5,99.0) progID="Shell.Explorer" name="r1" initFlag="r1init"
 
// embed control
if V[r1init] 
  callvb simple_form.create_order.embed "&V[r1]"  
endif
InputScript "create_simple_order.txt":

Parameter ORDERTYPE
Enter "/nVA01"
 
// Create Sales Order: Initial Screen 
Screen SAPMV45A.0101
  Set F[Order Type] "&U[ORDERTYPE]"
  Enter
 
// Create Standard Order: Overview 
Screen SAPMV45A.4001
  Set F[Sold-To Party]    "&V[customerno]"
  Set F[PO Number]    "&V[orderno]"
  Set cell[All items,Material,1]       "&V[matno]"
  Set cell[All items,Order Quantity,1]       "&V[quant]"
  
Download:

Download the .NET project with source-code:
simple_form_dotnet.zip

Components InputAssistant + Controls