0

I am working on an app in C# for Rpi 3 (running windows IoT Core). It will need to be able to get input from a keyboard (phisycal, not onscreen) and be able to put that input in a string so it can easily be shown on a monitor (using xaml).

However I am not sure how to capture that input. Is this baked into the OS already? If not, what do I need to do to ask for input and put that input in a string? Maybe the answer is very simple but as of yet I've not really been able to find a good answer to this question. Been working with C# for about 5 weeks now so still a bit of a noob..

Cheers

1 Answer 1

0

Keyboard input should 'just work'- you shouldn't have to do anything aside from plugging the keyboard in.

Quick example, starting from a blank UWP application:

XAML (Mainpage.xaml):

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto"/>
        <ColumnDefinition Width="Auto"/>
    </Grid.ColumnDefinitions>
    <!-- Box to take user input -->
    <TextBox Grid.Row="0" Grid.Column="0" Name="MyTextBox" Width="400"/>
    <!-- Button to confirm input - note the Click event handler -->
    <Button Grid.Row="0" Grid.Column="1" Name="MyButton" Width="60" Height="60" Content="OK" Click="MyButton_Click"/>
    <!-- TextBlock displays text from TextBox on Button click -->
    <TextBlock Grid.Row="1" Grid.ColumnSpan="2" Name="MyTextBlock" />
</Grid>

Codebehind/C# (Mainpage.xaml.cs):

public sealed partial class MainPage : Page
{
    public MainPage()
    {
        this.InitializeComponent();
    }

    //Click event handler for MyButton
    private void MyButton_Click(object sender, RoutedEventArgs e)
    {
        //Take the string value Text from MyTextBox (the user input) and assign it to the string value Text for MyTextBlock
        MyTextBlock.Text = MyTextBox.Text;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.