Skip to main content
Post

How to Implement OnKeyDown/OnKeyPress Behavior in PowerApps Text Input: Creative Control Workarounds by Paulie M

How to Implement OnKeyDown/OnKeyPress Behavior in PowerApps Text Input: Creative Control Workarounds by Paulie M

TL;DR: Power Apps text inputs have no OnKeyDown or OnKeyPress. The Text property updates as the user types, so formulas that read it recalculate live. To run an action on each change, bind a hidden Slider or Toggle to the text (Slider1.Default = Len(TextInput1.Text)) and put the action in that control’s OnChange or OnCheck.

Paulie M works around a real gap in Power Apps: the Text input control has no per-key event, and OnChange is not a keystroke event.

💡 Challenge

You want something to happen while the user types: store the last typed character, count keystrokes, start a lookup once three characters are entered. In Power Apps, TextInput.OnChange doesn’t help here. In the modern Text input it fires when the user leaves the field (on blur), not on every keystroke, and there is no OnKeyDown or OnKeyPress property at all.

✅ Solution

Separate the two kinds of formulas:

🔸 Data formulas (a gallery’s Items, a label’s Text, a Visible rule) that reference TextInput1.Text recalculate as the user types. They need no workaround.

🔸 Behavior formulas (Set, Collect, Patch, Notify) only run inside events. For those, Paulie M binds a hidden control’s default value to the text input. Each change of the text changes that default, and the hidden control’s own event runs your behavior formula.

🔧 How It’s Done

1. Make the text update while typing

🔸 Classic Text input: the Text property updates as the user types. Set DelayOutput to true if you want the update only after half a second without typing.

🔸 Modern Text input: set TriggerOutput to TriggerOutput.Keypress (the default outside forms). TriggerOutput.Delayed updates after a short pause, TriggerOutput.FocusOut only when the user leaves the field.

2. Live search without any workaround

// Gallery1.Items
If(
    Len(TextInput1.Text) >= 3,
    Filter(Customers, StartsWith(Name, TextInput1.Text)),
    Customers
)

3. Run an action on every change: hidden Slider

🔸 Add a Slider, set Visible to false, Max to the longest text you expect (for example TextInput1.MaxLength or 1000) and:

// Slider1.Default
Len(TextInput1.Text)

// Slider1.OnChange
If(
    Len(TextInput1.Text) > Len(varPreviousText),
    Set(varLastChar, Right(TextInput1.Text, 1)),
    Set(varLastChar, "")
);
Set(varPreviousText, TextInput1.Text)

🔸 Every typed or deleted character changes the length, so Slider1.OnChange runs and compares the new text with the stored previous value: a character was added (and which one) or removed.

4. Run an action at a threshold: hidden Toggle

🔸 For “do something once the input reaches 3 characters”, a Toggle is enough:

// Toggle1.Default
Len(TextInput1.Text) >= 3

// Toggle1.OnCheck
Notify("Searching for " & TextInput1.Text)

🔸 OnCheck runs when the condition becomes true, OnUncheck when the user deletes below the threshold.

🎉 Result

The app reacts while the user types: live search through a normal data formula, and actions such as storing the last character or counting edits through the hidden Slider or Toggle.

🌟 Key Advantages

🔸 No code component: only standard controls and Power Fx.

🔸 Clear split: live data formulas stay simple, the hidden control is only used where a behavior formula is needed.

🔸 Tunable: DelayOutput or TriggerOutput.Delayed keep expensive formulas from running on every single key.

⚠️ Good to Know

🔸 The pattern reacts to the resulting text, not to a key. Enter, arrow keys or Tab in a single-line input don’t change the text and are not detected. Two keystrokes that produce the same text look identical.

🔸 Keep the helper control invisible so users can’t move it and change its value themselves.

🔸 Expensive actions (a Patch per keystroke, a flow call) belong behind a threshold or a delayed output, not on every character.

🛠️ FAQ

1. Do Power Apps text inputs support OnKeyDown or OnKeyPress events?

No. The Text input control has no per-key event. Its Text property updates while the user types, but OnChange is not a keystroke event: in the modern Text input it fires when the user leaves the field.

2. How can I run an action on every keystroke?

Bind a hidden Slider or Toggle to the text input, for example Slider1.Default = Len(TextInput1.Text). When the text changes, the default changes, and the hidden control’s OnChange or OnCheck runs your action. This is the pattern Paulie M shows in the video.

3. Do I need the workaround for a live search?

No. A gallery whose Items formula references TextInput1.Text recalculates as the user types. The workaround is only needed for behavior formulas such as Set, Collect or Patch.

4. What are the limits of the workaround?

It reacts to the resulting text, not to a key. Keys that don’t change the text, such as Enter, arrows or Tab in a single-line input, are not detected, and two keystrokes that produce the same text look identical.

🔸 #PowerPlatformTip 108: ‘Double-Click Magic in PowerApps’ - another event Power Apps doesn’t offer natively, built from standard controls.

🔸 #PowerPlatformTip 78: ‘Efficient Control Reset’ - reset the text input and its hidden helper controls together.

🔸 #PowerPlatformTip 23: ‘Filter Blank’ - show all gallery items while the search box is still empty.


You can see this video here on my blog because I have rated this video with 5 stars in my YouTube video library. This video was automatically posted using PowerAutomate.

This tip is by Marcel Lehmann, Microsoft MVP (Business Applications) and founder of the Power Platform Academy, which runs free live workshops (in German). See the next free workshop dates (in German). For companies that want this implemented for them, see KMUpower: Power Platform consulting & automation for SMEs (DACH).

This post is licensed under CC BY 4.0 by the author.

Microsoft and the Power Platform product names (for example Power Apps, Power Automate, Copilot Studio) are trademarks of the Microsoft group of companies. This is an independent website. It is not operated, sponsored or endorsed by Microsoft.