Skip to content

Keyboard

updateKeyboard

TIP

The API usage is as follows: wx.updateKeyboard(Object object)

  • Functional description: Update the content of the keyboard input box. It will only take effect when the keyboard is pulled up.
  • Parameters and descriptions: Object object。
PropertiesTypeDefault valueRequiredDescription
valuestring-YesCurrent value of the keyboard input box
successFunction-NoCallback function for successful interface call
failFunction-NoCallback function for failed interface call
completeFunction-NoCallback function for interface call completion (executed regardless of success or failure)

showKeyboard

TIP

The API usage is as follows: wx.showKeyboard(Object object)

  • Functional description: Show the keyboard.
  • Parameters and descriptions: Object object。
PropertiesTypeDefault valueRequiredDescription
defaultValuestring-YesDefault value displayed in the keyboard input box
maxLengthnumber-YesMaximum length of text in the keyboard
multipleboolean-YesIs it multi-line input
confirmHoldboolean-YesWhether the keyboard remains displayed when clicking Done
confirmTypestring-YesThe type of the confirm button in the lower right corner of the keyboard, which only affects the text content of the button
successFunction-NoCallback function for successful interface call
failFunction-NoCallback function for failed interface call
completeFunction-NoCallback function for interface call completion (executed regardless of success or failure)
  • confirmType Legal value

    Legal valueDescription
    doneDone
    nextNext
    searchSearch
    goGo
    sendSend

onKeyboardInput

TIP

The API usage is as follows: wx.onKeyboardInput(function listener)

  • Functional description: Listen for keyboard input events.

  • Parameters and descriptions: function listener, Listen for keyboard input events, parameters are as follows:

    PropertiesTypeDescription
    valuestringCurrent value of keyboard input

onKeyboardHeightChange

TIP

The API usage is as follows: wx.onKeyboardHeightChange(function listener)

  • Functional description: Listen for keyboard height change events.

  • Parameters and descriptions: function listener, Listen for keyboard height change events, parameters are as follows:

  • Object res。

    PropertiesTypeDescription
    heightnumberKeyboard height
  • Sample code:

js
wx.onKeyboardHeightChange((res) => {
  console.log(res.height);
});

onKeyboardConfirm

TIP

The API usage is as follows: wx.onKeyboardConfirm(function listener)

  • Functional description: Listen for events when the user clicks the Confirm button on the keyboard.

  • Parameters and descriptions: function listener, Listen for events when the user clicks the Confirm button on the keyboard, parameters are as follows:

    PropertiesTypeDescription
    valuestringCurrent value of keyboard input

onKeyboardComplete

TIP

The API usage is as follows: wx.onKeyboardComplete(function listener)

  • Functional description: Listen for keyboard retraction events.

  • Parameters and descriptions: function listener, Listen for keyboard retraction events, parameters are as follows:

    PropertiesTypeDescription
    valuestringCurrent value of keyboard input

offKeyboardInput

TIP

The API usage is as follows: wx.offKeyboardInput(function listener)

  • Functional description: Remove the listener for keyboard input events.
  • Parameters and descriptions: function listener, Listener function passed in by onKeyboardInput. If this parameter is not passed, all listeners are removed.
  • Sample code:
js
const listener = function (res) {
  console.log(res);
};
wx.onKeyboardInput(listener);
d;
wx.offKeyboardInput(listener); // Must pass the same function object used in onKeyboardInput

offKeyboardHeightChange

TIP

The API usage is as follows: wx.offKeyboardHeightChange(function listener)

  • Functional description: Remove the listener for keyboard height change events.
  • Parameters and descriptions: function listener, Listener function passed in by onKeyboardHeightChange. If this parameter is not passed, all listeners are removed.
  • Sample code:
js
const listener = function (res) {
  console.log(res);
};
wx.onKeyboardHeightChange(listener);
wx.offKeyboardHeightChange(listener); // Must pass the same function object used in onKeyboardHeightChange

offKeyboardConfirm

TIP

The API usage is as follows: wx.offKeyboardConfirm(function listener)

  • Functional description: Remove the listener for events when the user clicks the Confirm button on the keyboard.
  • Parameters and descriptions: function listener, Listener function passed in by onKeyboardConfirm. If this parameter is not passed, all listeners are removed.
  • Sample code:
js
const listener = function (res) {
  console.log(res);
};

wx.onKeyboardConfirm(listener);
wx.offKeyboardConfirm(listener); // Must pass the same function object used in onKeyboardConfirm

offKeyboardComplete

TIP

The API usage is as follows: wx.offKeyboardComplete(function listener)

  • Functional description: Remove the listener for events when the keyboard is retracted.
  • Parameters and descriptions: function listener, Listener function passed in by onKeyboardComplete. If this parameter is not passed, all listening functions will be removed.
  • Sample code:
js
const listener = function (res) {
  console.log(res);
};

wx.onKeyboardComplete(listener);
wx.offKeyboardComplete(listener); // Must pass the same function object used in onKeyboardComplete

hideKeyboard

TIP

The API usage is as follows: wx.hideKeyboard(Object object)

  • Functional description: Hide the keyboard

  • Parameters and descriptions: Object object。

    PropertiesTypeDefault valueRequiredDescription
    successFunction-NoCallback function for successful interface call
    failFunction-NoCallback function for failed interface call
    completeFunction-NoCallback function for interface call completion (executed regardless of success or failure)
  • Sample code:

js
wx.hideKeyboard({
  complete: (res) => {
    console.log("hideKeyboard res", res);
  },
});