@@ -255,6 +255,12 @@ public class PApplet extends Object implements ActivityAPI, PConstants {
255
255
*/
256
256
protected boolean keyRepeatEnabled = false ;
257
257
258
+ /**
259
+ * Set to open when openKeyboard() is called, and used to close the keyboard when the sketch is
260
+ * paused, otherwise it remains visible.
261
+ */
262
+ boolean keyboardIsOpen = false ;
263
+
258
264
///////////////////////////////////////////////////////////////
259
265
// Permission handling
260
266
@@ -2493,15 +2499,19 @@ public void openKeyboard() {
2493
2499
Context context = surface .getContext ();
2494
2500
InputMethodManager imm = (InputMethodManager )context .getSystemService (Context .INPUT_METHOD_SERVICE );
2495
2501
imm .toggleSoftInput (InputMethodManager .SHOW_FORCED ,0 );
2502
+ keyboardIsOpen = true ;
2496
2503
}
2497
2504
2498
2505
2499
2506
public void closeKeyboard () {
2500
- Context context = surface .getContext ();
2501
- InputMethodManager imm = (InputMethodManager )context .getSystemService (Context .INPUT_METHOD_SERVICE );
2502
- imm .toggleSoftInput (InputMethodManager .HIDE_IMPLICIT_ONLY , 0 );
2503
- if (parentLayout == -1 ) {
2504
- setFullScreenVisibility ();
2507
+ if (keyboardIsOpen ) {
2508
+ Context context = surface .getContext ();
2509
+ InputMethodManager imm = (InputMethodManager ) context .getSystemService (Context .INPUT_METHOD_SERVICE );
2510
+ imm .toggleSoftInput (InputMethodManager .HIDE_IMPLICIT_ONLY , 0 );
2511
+ keyboardIsOpen = false ;
2512
+ if (parentLayout == -1 ) {
2513
+ setFullScreenVisibility ();
2514
+ }
2505
2515
}
2506
2516
}
2507
2517
0 commit comments