virtual-keyboard https://www.e-learn.cn/tag/virtual-keyboard zh-hans Qt Virtual Keyboard in QQuickWidget https://www.e-learn.cn/topic/4117194 <span>Qt Virtual Keyboard in QQuickWidget</span> <span><span lang="" about="/user/211" typeof="schema:Person" property="schema:name" datatype="">夙愿已清</span></span> <span>2021-02-19 06:23:08</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>It is possible to show Virtual Keyboard in QQuickWidget or in QWidget?</p> <p>I have QWidget application and I need to have better control where VirtualKeyboard is shown.</p> <p>Today I spend all my day to find a solution, unfortunately without success.</p> <br /><h3>回答1:</h3><br /><p>The following code shows that it is valid to use virtualkeyboard in QQuickWidget.</p> <p><strong>main.cpp</strong></p> <pre class="lang-cpp prettyprint-override"><code>#include &lt;QApplication&gt; #include &lt;QQmlApplicationEngine&gt; #include &lt;QQuickWidget&gt; int main(int argc, char *argv[]) { qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard")); QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QApplication app(argc, argv); QQuickWidget widget; widget.setResizeMode(QQuickWidget::SizeRootObjectToView); widget.setSource(QStringLiteral("qrc:/main.qml")); widget.show(); return app.exec(); } </code></pre> <p><strong>main.qml</strong></p> <pre><code>import QtQuick 2.14 import QtQuick.Window 2.14 import QtQuick.VirtualKeyboard 2.14 Rectangle { id: window width: 640 height: 480 TextEdit{ text: "Hello world" anchors.centerIn: parent } InputPanel { id: inputPanel z: 99 x: 0 y: window.height width: window.width states: State { name: "visible" when: inputPanel.active PropertyChanges { target: inputPanel y: window.height - inputPanel.height } } transitions: Transition { from: "" to: "visible" reversible: true ParallelAnimation { NumberAnimation { properties: "y" duration: 250 easing.type: Easing.InOutQuad } } } } } </code></pre> <p><strong>qml.qrc</strong></p> <pre><code>&lt;RCC&gt; &lt;qresource prefix="/"&gt; &lt;file&gt;main.qml&lt;/file&gt; &lt;/qresource&gt; &lt;/RCC&gt; </code></pre> <p><strong>59777221.pro</strong></p> <pre><code>QT += quickwidgets virtualkeyboard CONFIG += c++11 DEFINES += QT_DEPRECATED_WARNINGS SOURCES += main.cpp RESOURCES += qml.qrc </code></pre> <pre><code>├── 59777221.pro ├── main.cpp ├── main.qml └── qml.qrc </code></pre> <p></p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/59777221/qt-virtual-keyboard-in-qquickwidget</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/qt" hreflang="zh-hans">qt</a></div> <div class="field--item"><a href="/tag/qt5" hreflang="zh-hans">qt5</a></div> <div class="field--item"><a href="/tag/virtual-keyboard" hreflang="zh-hans">virtual-keyboard</a></div> <div class="field--item"><a href="/tag/qquickwidget" hreflang="zh-hans">qquickwidget</a></div> </div> </div> Thu, 18 Feb 2021 22:23:08 +0000 夙愿已清 4117194 at https://www.e-learn.cn Use a virtual Keyboard on focused Textboxes and DataGridView Cells https://www.e-learn.cn/topic/4094122 <span>Use a virtual Keyboard on focused Textboxes and DataGridView Cells</span> <span><span lang="" about="/user/46" typeof="schema:Person" property="schema:name" datatype="">最后都变了-</span></span> <span>2021-02-11 07:38:21</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>In my Form I have various Textboxes that I write into with an in Form keyboard I created using Buttons. I have this code in Form.Load, which uses an event handler to determine which Textbox has the Focus:</p> <pre><code>For Each control As Control In Me.Controls If control.GetType.Equals(GetType(TextBox)) Then Dim textBox As TextBox = control AddHandler textBox.Enter, Sub() FocussedTextbox = textBox End If Next </code></pre> <p>Then I use this on each button to write a specific character:</p> <pre><code>Private Sub btnQ_Click(sender As Object, e As EventArgs) Handles btnQ.Click If btnQ.Text = "Q" Then FocussedTextbox.Text += "Q" ElseIf btnQ.Text = "q" Then FocussedTextbox.Text += "q" End If End Sub </code></pre> <p>Up to that point I'm good and everything works as intended. The problem is I also have a <code>DataGridView</code> I want to write into but can't focus on it selected cells as I do on Textboxes.</p> <p>I tried this:</p> <pre><code>For Each control As Control In Me.Controls If control.GetType.Equals(GetType(TextBox)) Then Dim textBox As TextBox = control AddHandler textBox.Enter, Sub() FocussedTextbox = textBox ElseIf control.GetType.Equals(GetType(DataGridViewCell)) Then Dim DGVC As DataGridView = control AddHandler DGVC.CellBeginEdit, Sub() FocussedTextbox = DGVC End If Next </code></pre> <p>But it just selects my last Textbox.</p> <p>I declared the variable <code>FocussedTextbox</code> as <code>Control</code> so it's not specific to Textbox but any control.</p> <p>Any help will be greatly appreciated.</p> <br /><h3>回答1:</h3><br /><p>To add text to the current ActiveControl using Buttons, these Button must not steal the focus from the ActiveControl (otherwise they become the ActiveControl).<br /> This way, you can also avoid all those <code>FocusedTextbox = textBox</code> etc. and remove that code.</p> <p>You just need Buttons that don't have the Selectable attribute set. You can use a Custom Control derived from Button and remove ControlStyles.Selectable in its constructor using the SetStyle method:</p> <pre><code>Public Class ButtonNoSel Inherits Button Public Sub New() SetStyle(ControlStyles.Selectable, False) End Sub End Class </code></pre> <p>Replace your Buttons with this one (or, well, just set the Style if you're already using Custom Controls).</p> <hr /><p>To replace the existing Buttons with this Custom Control:</p> <ul><li>Add a new class object to your Project, name it <code>ButtonNoSel</code>, copy all the code above inside the new class to replace the two lines of code you find there.</li> <li>Build the Project. You can find the <code>ButtonNoSel</code> Control in your ToolBox now. Replace your Buttons with this one.</li> <li>Or, open up the Form's Designer file and replace (<kbd>CTRL+H</kbd>) all <code>System.Windows.Forms.Button()</code> related to the Virtual KeyBoard with <code>ButtonNoSel</code>.</li> <li>Remove the existing event handlers, these are not needed anymore.</li> </ul><hr /><p>Add the same Click event handler in the Constructor of the class that hosts those Buttons (a Form or whatever else you're using).<br /> You can then remove all those event handlers, one for each control, that you have now; only one event handler is needed for all:</p> <pre><code>Public Sub New() InitializeComponent() For Each ctrl As Control In Me.Controls.OfType(Of ButtonNoSel) AddHandler ctrl.Click, AddressOf KeyBoardButtons_Click Next End Sub </code></pre> <p>Of course, you also don't need to add event handlers to any other control, this is all that's required.</p> <p>Now, you can filter the Control types you want your keyboard to work on, e.g., TextBoxBase Controls (TextBox and RichTextBox), DataGridView, NumericUpDown etc.<br /> Or filter only special cases that need <em>special treatment</em> (e.g., MonthCalendar).</p> <p>To add the char corresponding to the Button pressed, you can use SendKeys.Send(): it will insert the new char in the current insertion point, so you don't need any other code to store and reset the caret/cursor position as it happens if you set the Text property of a Control.</p> <p>In this example, I'm checking whether the <code>ActiveControl</code> is a <code>TextBoxBase</code> Control, then just send the char that the clicked Button holds.<br /> If it's a DataGridView, first send <code>F2</code> to enter Edit Mode, then send the char.<br /> You could also just send a char (so, no filter would be required), but in this case, you'll replace, not add to, the existing value of that Cell.</p> <pre><code>Private Sub KeyBoardButtons_Click(sender As Object, e As EventArgs) Dim selectedButton = DirectCast(sender, Control) Dim keysToSend = String.Empty If TypeOf ActiveControl Is TextBoxBase Then keysToSend = selectedButton.Text ElseIf TypeOf ActiveControl Is DataGridView Then Dim ctrl = DirectCast(ActiveControl, DataGridView) If TypeOf ctrl.CurrentCell IsNot DataGridViewTextBoxCell Then Return SendKeys.Send("{F2}") keysToSend = selectedButton.Text Else ' Whatever else End If If Not String.IsNullOrEmpty(keysToSend) Then SendKeys.Send(keysToSend) End If End Sub </code></pre> <p>► Note that <code>{F2}</code> is sent just once: when the Cell enters Edit Mode, the <code>ActiveControl</code> is a <strong><code>DataGridViewTextBoxEditingControl</code></strong>, hence a TextBox Control, handled by the <code>TextBoxBase</code> filter.</p> <p>This is how it works (using just the code posted here):</p> <p></p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/64225955/use-a-virtual-keyboard-on-focused-textboxes-and-datagridview-cells</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/vbnet" hreflang="zh-hans">vb.net</a></div> <div class="field--item"><a href="/tag/winforms" hreflang="zh-hans">winforms</a></div> <div class="field--item"><a href="/tag/datagridview" hreflang="zh-hans">datagridview</a></div> <div class="field--item"><a href="/tag/virtual-keyboard" hreflang="zh-hans">virtual-keyboard</a></div> </div> </div> Wed, 10 Feb 2021 23:38:21 +0000 最后都变了- 4094122 at https://www.e-learn.cn Use a virtual Keyboard on focused Textboxes and DataGridView Cells https://www.e-learn.cn/topic/4094118 <span>Use a virtual Keyboard on focused Textboxes and DataGridView Cells</span> <span><span lang="" about="/user/136" typeof="schema:Person" property="schema:name" datatype="">扶醉桌前</span></span> <span>2021-02-11 07:37:51</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>In my Form I have various Textboxes that I write into with an in Form keyboard I created using Buttons. I have this code in Form.Load, which uses an event handler to determine which Textbox has the Focus:</p> <pre><code>For Each control As Control In Me.Controls If control.GetType.Equals(GetType(TextBox)) Then Dim textBox As TextBox = control AddHandler textBox.Enter, Sub() FocussedTextbox = textBox End If Next </code></pre> <p>Then I use this on each button to write a specific character:</p> <pre><code>Private Sub btnQ_Click(sender As Object, e As EventArgs) Handles btnQ.Click If btnQ.Text = "Q" Then FocussedTextbox.Text += "Q" ElseIf btnQ.Text = "q" Then FocussedTextbox.Text += "q" End If End Sub </code></pre> <p>Up to that point I'm good and everything works as intended. The problem is I also have a <code>DataGridView</code> I want to write into but can't focus on it selected cells as I do on Textboxes.</p> <p>I tried this:</p> <pre><code>For Each control As Control In Me.Controls If control.GetType.Equals(GetType(TextBox)) Then Dim textBox As TextBox = control AddHandler textBox.Enter, Sub() FocussedTextbox = textBox ElseIf control.GetType.Equals(GetType(DataGridViewCell)) Then Dim DGVC As DataGridView = control AddHandler DGVC.CellBeginEdit, Sub() FocussedTextbox = DGVC End If Next </code></pre> <p>But it just selects my last Textbox.</p> <p>I declared the variable <code>FocussedTextbox</code> as <code>Control</code> so it's not specific to Textbox but any control.</p> <p>Any help will be greatly appreciated.</p> <br /><h3>回答1:</h3><br /><p>To add text to the current ActiveControl using Buttons, these Button must not steal the focus from the ActiveControl (otherwise they become the ActiveControl).<br /> This way, you can also avoid all those <code>FocusedTextbox = textBox</code> etc. and remove that code.</p> <p>You just need Buttons that don't have the Selectable attribute set. You can use a Custom Control derived from Button and remove ControlStyles.Selectable in its constructor using the SetStyle method:</p> <pre><code>Public Class ButtonNoSel Inherits Button Public Sub New() SetStyle(ControlStyles.Selectable, False) End Sub End Class </code></pre> <p>Replace your Buttons with this one (or, well, just set the Style if you're already using Custom Controls).</p> <hr /><p>To replace the existing Buttons with this Custom Control:</p> <ul><li>Add a new class object to your Project, name it <code>ButtonNoSel</code>, copy all the code above inside the new class to replace the two lines of code you find there.</li> <li>Build the Project. You can find the <code>ButtonNoSel</code> Control in your ToolBox now. Replace your Buttons with this one.</li> <li>Or, open up the Form's Designer file and replace (<kbd>CTRL+H</kbd>) all <code>System.Windows.Forms.Button()</code> related to the Virtual KeyBoard with <code>ButtonNoSel</code>.</li> <li>Remove the existing event handlers, these are not needed anymore.</li> </ul><hr /><p>Add the same Click event handler in the Constructor of the class that hosts those Buttons (a Form or whatever else you're using).<br /> You can then remove all those event handlers, one for each control, that you have now; only one event handler is needed for all:</p> <pre><code>Public Sub New() InitializeComponent() For Each ctrl As Control In Me.Controls.OfType(Of ButtonNoSel) AddHandler ctrl.Click, AddressOf KeyBoardButtons_Click Next End Sub </code></pre> <p>Of course, you also don't need to add event handlers to any other control, this is all that's required.</p> <p>Now, you can filter the Control types you want your keyboard to work on, e.g., TextBoxBase Controls (TextBox and RichTextBox), DataGridView, NumericUpDown etc.<br /> Or filter only special cases that need <em>special treatment</em> (e.g., MonthCalendar).</p> <p>To add the char corresponding to the Button pressed, you can use SendKeys.Send(): it will insert the new char in the current insertion point, so you don't need any other code to store and reset the caret/cursor position as it happens if you set the Text property of a Control.</p> <p>In this example, I'm checking whether the <code>ActiveControl</code> is a <code>TextBoxBase</code> Control, then just send the char that the clicked Button holds.<br /> If it's a DataGridView, first send <code>F2</code> to enter Edit Mode, then send the char.<br /> You could also just send a char (so, no filter would be required), but in this case, you'll replace, not add to, the existing value of that Cell.</p> <pre><code>Private Sub KeyBoardButtons_Click(sender As Object, e As EventArgs) Dim selectedButton = DirectCast(sender, Control) Dim keysToSend = String.Empty If TypeOf ActiveControl Is TextBoxBase Then keysToSend = selectedButton.Text ElseIf TypeOf ActiveControl Is DataGridView Then Dim ctrl = DirectCast(ActiveControl, DataGridView) If TypeOf ctrl.CurrentCell IsNot DataGridViewTextBoxCell Then Return SendKeys.Send("{F2}") keysToSend = selectedButton.Text Else ' Whatever else End If If Not String.IsNullOrEmpty(keysToSend) Then SendKeys.Send(keysToSend) End If End Sub </code></pre> <p>► Note that <code>{F2}</code> is sent just once: when the Cell enters Edit Mode, the <code>ActiveControl</code> is a <strong><code>DataGridViewTextBoxEditingControl</code></strong>, hence a TextBox Control, handled by the <code>TextBoxBase</code> filter.</p> <p>This is how it works (using just the code posted here):</p> <p></p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/64225955/use-a-virtual-keyboard-on-focused-textboxes-and-datagridview-cells</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/vbnet" hreflang="zh-hans">vb.net</a></div> <div class="field--item"><a href="/tag/winforms" hreflang="zh-hans">winforms</a></div> <div class="field--item"><a href="/tag/datagridview" hreflang="zh-hans">datagridview</a></div> <div class="field--item"><a href="/tag/virtual-keyboard" hreflang="zh-hans">virtual-keyboard</a></div> </div> </div> Wed, 10 Feb 2021 23:37:51 +0000 扶醉桌前 4094118 at https://www.e-learn.cn What is the keycode for “Next” in android virtualKeyBoard https://www.e-learn.cn/topic/4081367 <span>What is the keycode for “Next” in android virtualKeyBoard</span> <span><span lang="" about="/user/49" typeof="schema:Person" property="schema:name" datatype="">帅比萌擦擦*</span></span> <span>2021-02-08 16:56:35</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I am enhancing (in an angular directive) the google places autocomplete input to select the first option if none is selected.</p> <p>I am using the below code, which works like a charm when using "tab" or "enter" key.</p> <p>Unfortunatly it is not working on android device (chrome) whith <strong>virtualkeyboard "next" key</strong>... </p> <p>What could be the KeyCode of this "<strong>next</strong>" key as it is neither "tab" (9) or "enter" (13)</p> <pre><code>selectFirstOnEnterOrTab(input) { // prevent submit on enter (13) $(input).keydown(function (e) { if (e.which === 13 &amp;&amp; $('.pac-container:visible').length) { return false; } }); // store the original event binding function const _addEventListener = (input.addEventListener) ? input.addEventListener : input.attachEvent; function addEventListenerWrapper(type, listener) { // Simulate a 'down arrow' keypress on hitting 'return' when no pac suggestion is selected, // and then trigger the original listener. if (type === 'keydown') { const orig_listener = listener; listener = function (event) { const suggestion_selected = $('.pac-item-selected').length &gt; 0; if ((event.which &gt;= 9 &amp;&amp; event.which &lt;= 13) &amp;&amp; !suggestion_selected) { const simulated_downarrow = $.Event('keydown', { keyCode: 40, which: 40 }); orig_listener.apply(input, [simulated_downarrow]); } orig_listener.apply(input, [event]); }; } _addEventListener.apply(input, [type, listener]); // add the modified listener } if (input.addEventListener) { input.addEventListener = addEventListenerWrapper; } else if (input.attachEvent) { input.attachEvent = addEventListenerWrapper; } } </code></pre> <p><strong>EDIT</strong></p> <p>Following Pitto suggestion, I have logged which and keycode on my android device, and for all the key I press, I receive 229, which apparently is a normal behaviour for android. Any ideas on how I can update my code for it to work on Android device too...</p> <p><strong>EDIT2</strong></p> <p>On android, on "next" pressed, there is no <strong>keydown</strong> event fired</p> <br /><h3>回答1:</h3><br /><p>Can you try to set a minimal page with this code and see if it prints the right value?</p> <pre><code>document.body.addEventListener("keyup", function(event) { console.log(event.key); console.log(event.code); }); </code></pre> <p>Or, even easier, you can get keycodes using this website:<br /> https://keycode.info</p> <p>The tab key data for my Samsung S10e, as returned by https://keycode.info:</p> <pre><code>event.key = Unidentified event.location = 0 event.which = 229 event.code = </code></pre> <br /><br /><br /><h3>回答2:</h3><br /><p>As pointed out already, the value for <code>e.which</code> / <code>e.keyCode</code> is going to be <code>229</code> and <code>e.key</code> is going to be <code>'Unidentified'</code>. You can check that using https://keyjs.dev, where you will also find an explanation about virtual/mobile keyboards:</p> <blockquote> <p>When using virtual/mobile keyboards, formally know as IME (Input-Method Editor), the W3C standard states that a KeyboardEvent's e.keyCode should be 229 and e.key should be "Unidentified".</p> </blockquote> <p>The best option on mobile is probably just adding an expand/down arrow to the dropdown and let users open it manually if they want to.</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/58081977/what-is-the-keycode-for-next-in-android-virtualkeyboard</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/javascript" hreflang="zh-hans">javascript</a></div> <div class="field--item"><a href="/tag/angular" hreflang="zh-hans">angular</a></div> <div class="field--item"><a href="/tag/virtual-keyboard" hreflang="zh-hans">virtual-keyboard</a></div> </div> </div> Mon, 08 Feb 2021 08:56:35 +0000 帅比萌擦擦* 4081367 at https://www.e-learn.cn JavaFX Virtual Keyboard doesn't show https://www.e-learn.cn/topic/3097368 <span>JavaFX Virtual Keyboard doesn&#039;t show</span> <span><span lang="" about="/user/54" typeof="schema:Person" property="schema:name" datatype="">↘锁芯ラ</span></span> <span>2020-01-04 09:57:25</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I'm new to javafx. I made a simple app form. It has </p> <ul><li>Anchor Pane</li> <li>Pane</li> <li>Text field</li> </ul><p>I run that app on touch screen device, but the virtual keyboard doesn't show up. The textfield already focused.</p> <p>I'm using JDK 8u25, scene builder 2.0.</p> <p>According to what I read, http://docs.oracle.com/javase/8/javafx/user-interface-tutorial/embed.htm </p> <blockquote> <p>The virtual keyboard is shown automatically when a text input field is in focus. Note that the control that is associated with the keyboard remains visible when the keyboard is displayed. There is no need to push the parent stage up.</p> </blockquote> <p>What should I do? Thanks in advance.</p> <br /><h3>回答1:</h3><br /><p>Adding the following arguments to your VM Options should allow the virtual keyboard to pop up:</p> <pre><code>-Dcom.sun.javafx.isEmbedded=true -Dcom.sun.javafx.virtualKeyboard=javafx </code></pre> <p>After that, you can specify the keyboard format as indicated in the JavaFX: Working with JavaFX UI Components document.</p> <p>For example, on a TextField named textField, use the following:</p> <pre><code>textField.getProperties().put("vkType", "numeric"); </code></pre> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/26777350/javafx-virtual-keyboard-doesnt-show</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/javafx-8" hreflang="zh-hans">javafx-8</a></div> <div class="field--item"><a href="/tag/fxml" hreflang="zh-hans">fxml</a></div> <div class="field--item"><a href="/tag/virtual-keyboard" hreflang="zh-hans">virtual-keyboard</a></div> </div> </div> Sat, 04 Jan 2020 01:57:25 +0000 ↘锁芯ラ 3097368 at https://www.e-learn.cn JavaFX Virtual Keyboard doesn't show https://www.e-learn.cn/topic/3097357 <span>JavaFX Virtual Keyboard doesn&#039;t show</span> <span><span lang="" about="/user/199" typeof="schema:Person" property="schema:name" datatype="">北城以北</span></span> <span>2020-01-04 09:56:46</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I'm new to javafx. I made a simple app form. It has </p> <ul><li>Anchor Pane</li> <li>Pane</li> <li>Text field</li> </ul><p>I run that app on touch screen device, but the virtual keyboard doesn't show up. The textfield already focused.</p> <p>I'm using JDK 8u25, scene builder 2.0.</p> <p>According to what I read, http://docs.oracle.com/javase/8/javafx/user-interface-tutorial/embed.htm </p> <blockquote> <p>The virtual keyboard is shown automatically when a text input field is in focus. Note that the control that is associated with the keyboard remains visible when the keyboard is displayed. There is no need to push the parent stage up.</p> </blockquote> <p>What should I do? Thanks in advance.</p> <br /><h3>回答1:</h3><br /><p>Adding the following arguments to your VM Options should allow the virtual keyboard to pop up:</p> <pre><code>-Dcom.sun.javafx.isEmbedded=true -Dcom.sun.javafx.virtualKeyboard=javafx </code></pre> <p>After that, you can specify the keyboard format as indicated in the JavaFX: Working with JavaFX UI Components document.</p> <p>For example, on a TextField named textField, use the following:</p> <pre><code>textField.getProperties().put("vkType", "numeric"); </code></pre> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/26777350/javafx-virtual-keyboard-doesnt-show</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/javafx-8" hreflang="zh-hans">javafx-8</a></div> <div class="field--item"><a href="/tag/fxml" hreflang="zh-hans">fxml</a></div> <div class="field--item"><a href="/tag/virtual-keyboard" hreflang="zh-hans">virtual-keyboard</a></div> </div> </div> Sat, 04 Jan 2020 01:56:46 +0000 北城以北 3097357 at https://www.e-learn.cn JavaFX Virtual Keyboard doesn't show https://www.e-learn.cn/topic/3097354 <span>JavaFX Virtual Keyboard doesn&#039;t show</span> <span><span lang="" about="/user/130" typeof="schema:Person" property="schema:name" datatype="">半城伤御伤魂</span></span> <span>2020-01-04 09:56:26</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I'm new to javafx. I made a simple app form. It has </p> <ul><li>Anchor Pane</li> <li>Pane</li> <li>Text field</li> </ul><p>I run that app on touch screen device, but the virtual keyboard doesn't show up. The textfield already focused.</p> <p>I'm using JDK 8u25, scene builder 2.0.</p> <p>According to what I read, http://docs.oracle.com/javase/8/javafx/user-interface-tutorial/embed.htm </p> <blockquote> <p>The virtual keyboard is shown automatically when a text input field is in focus. Note that the control that is associated with the keyboard remains visible when the keyboard is displayed. There is no need to push the parent stage up.</p> </blockquote> <p>What should I do? Thanks in advance.</p> <br /><h3>回答1:</h3><br /><p>Adding the following arguments to your VM Options should allow the virtual keyboard to pop up:</p> <pre><code>-Dcom.sun.javafx.isEmbedded=true -Dcom.sun.javafx.virtualKeyboard=javafx </code></pre> <p>After that, you can specify the keyboard format as indicated in the JavaFX: Working with JavaFX UI Components document.</p> <p>For example, on a TextField named textField, use the following:</p> <pre><code>textField.getProperties().put("vkType", "numeric"); </code></pre> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/26777350/javafx-virtual-keyboard-doesnt-show</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/javafx-8" hreflang="zh-hans">javafx-8</a></div> <div class="field--item"><a href="/tag/fxml" hreflang="zh-hans">fxml</a></div> <div class="field--item"><a href="/tag/virtual-keyboard" hreflang="zh-hans">virtual-keyboard</a></div> </div> </div> Sat, 04 Jan 2020 01:56:26 +0000 半城伤御伤魂 3097354 at https://www.e-learn.cn JavaFX virtual keyboard overlaps nodes https://www.e-learn.cn/topic/3081110 <span>JavaFX virtual keyboard overlaps nodes</span> <span><span lang="" about="/user/207" typeof="schema:Person" property="schema:name" datatype="">流过昼夜</span></span> <span>2020-01-03 14:15:15</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>i have a question about using virtual keyboard on touch supported pc with Windows 8.1. I have managed to show the virtual keyboard when textfield is focused with java switch:</p> <pre><code>-Dcom.sun.javafx.isEmbedded=true -Dcom.sun.javafx.virtualKeyboard=javafx </code></pre> <p>I found how to that on JavaFX Virtual Keyboard doesn't show1.</p> <p>But when the keyboard show's up, it overlapps nodes below the keyboard.</p> <p>According to what I read, http://docs.oracle.com/javase/8/javafx/user-interface-tutorial/embed.htm, it should't be working like that.</p> <p>Does anyone have any experience with that kind of problem?</p> <p>When i run the test application it shows in full screen and embedded virtual keyboard is showing, becasue the textfield has focus. The textfield in this case is not visible until i "hide" the keyboard. I am not sure that this is the right approach so i need help please.</p> <pre><code>java -Dcom.sun.javafx.isEmbedded=true -Dcom.sun.javafx.virtualKeyboard=javafx application.TestVKB public class TestVKB extends Application{ public static void main(String[] args) { Application.launch(args); } @Override public void start(Stage stage) throws Exception { TextField tfComment = new TextField(); tfComment.setPromptText("Enter comment"); BorderPane borderPane = new BorderPane(); borderPane.setBottom(tfComment); Scene scene = new Scene(borderPane); stage.setScene(scene); stage.setMaximized(true); stage.show(); } } </code></pre> <p></p><p></p><img class="b-lazy" data-src="https://i0.wp.com/i.stack.imgur.com/D2uLt.png" data-original="https://i0.wp.com/i.stack.imgur.com/D2uLt.png" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" /><p></p> <p>After click in field username or password </p><p></p><img class="b-lazy" data-src="https://i0.wp.com/i.stack.imgur.com/sLW4k.png" data-original="https://i0.wp.com/i.stack.imgur.com/sLW4k.png" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" /><p></p> <p>I would be grateful for any advice. Thanks in advance.</p> <br /><h3>回答1:</h3><br /><p>As I've already pointed out in my first answer, the virtual keyboard is embedded in a <code>PopupWindow</code>, created in a different stage, and displayed on top of your current stage.</p> <p>The option <code>-Dcom.sun.javafx.vk.adjustwindow=true</code> works, moving the main stage so the control is visible and there is no overlapping.</p> <p>But when this input control is located at the bottom of the main stage, this is moved up to the center of the screen leaving a big empty gap that shows whatever is behind.</p> <p>This second answer gives a solution to move the main stage just the required distance, without any gap, also taking into account the fade in/out animations of the virtual keyboard.</p> <p>For starters, in our scene, we add a <code>Button</code> on the center, and the <code>TextField</code> on the bottom. With two controls we can change the focus easily and show/hide the keyboard.</p> <p>To maximize the stage I'll use <code>getVisualBounds()</code>, so the taskbar can be visible.</p> <pre><code>private PopupWindow keyboard; private final Rectangle2D visualBounds = Screen.getPrimary().getVisualBounds(); private final Rectangle2D bounds = Screen.getPrimary().getBounds(); private final double taskbarHeight=bounds.getHeight()-visualBounds.getHeight(); @Override public void start(Stage stage) { TextField tfComment = new TextField(); tfComment.setPromptText("Enter comment"); BorderPane borderPane = new BorderPane(new Button("Click")); borderPane.setBottom(tfComment); Scene scene = new Scene(borderPane); stage.setScene(scene); stage.setX(visualBounds.getMinX()); stage.setY(visualBounds.getMinY()); stage.setWidth(visualBounds.getWidth()); stage.setHeight(visualBounds.getHeight()); stage.show(); } </code></pre> <p>We need to find the new stage when it's shown. In the same way as Scenic View, we'll use a deprecated method to get a valid window:</p> <pre><code>private PopupWindow getPopupWindow() { @SuppressWarnings("deprecation") final Iterator&lt;Window&gt; windows = Window.impl_getWindows(); while (windows.hasNext()) { final Window window = windows.next(); if (window instanceof PopupWindow) { if(window.getScene()!=null &amp;&amp; window.getScene().getRoot()!=null){ Parent root = window.getScene().getRoot(); if(root.getChildrenUnmodifiable().size()&gt;0){ Node popup = root.getChildrenUnmodifiable().get(0); if(popup.lookup(".fxvk")!=null){ return (PopupWindow)window; } } } return null; } } return null; } </code></pre> <p>We'll call this method when the textfield gets the focus:</p> <pre><code> ... stage.show(); tfComment.focusedProperty().addListener((ob,b,b1)-&gt;{ if(keyboard==null){ keyboard=getPopupWindow(); } }); } </code></pre> <p>Once we have the window, we can listen to changes in its position and move the main stage accordingly:</p> <pre><code> .... stage.show(); //findWindowExecutor.execute(new WindowTask()); tfComment.focusedProperty().addListener((ob,b,b1)-&gt;{ if(keyboard==null){ keyboard=getPopupWindow(); keyboard.yProperty().addListener(obs-&gt;{ System.out.println("wi "+keyboard.getY()); Platform.runLater(()-&gt;{ double y = bounds.getHeight()-taskbarHeight-keyboard.getY(); stage.setY(y&gt;0?-y:0); }); }); } }); } </code></pre> <p>Note that instead of moving up the stage, another option will be resizing it (if there is enough space within the controls).</p> <p>This will be the case where the textfield gets the focus and the virtual keyboard is fully shown:</p> <p></p><p></p><img class="b-lazy" data-src="https://i0.wp.com/i.stack.imgur.com/JRGDE.png" data-original="https://i0.wp.com/i.stack.imgur.com/JRGDE.png" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" /><p></p> <br /><br /><br /><h3>回答2:</h3><br /><p>Basically, the virtual keyboard is embedded in a <code>PopupWindow</code>, created in a different stage, and displayed on top of your current stage, at the bottom of the screen, no matter where the <code>InputControl</code> that triggers the keyboard is located.</p> <p>You can see that on the <code>FXVKSkin</code> class:</p> <pre><code>winY.set(screenBounds.getHeight() - VK_HEIGHT); </code></pre> <p>But, just inmediately after that, you can find this:</p> <pre><code>if (vkAdjustWindow) { adjustWindowPosition(attachedNode); } </code></pre> <p>So, there's another command line option that you can use to move the stage so the node (the textfield in this case) will be on the center of the screen and you can type without overlapping it:</p> <pre><code>-Dcom.sun.javafx.vk.adjustwindow=true </code></pre> <p>Note that when the textfield loses the focus, the keyboard is hidden and the stage is moved again to its original position:</p> <pre><code>restoreWindowPosition(oldNode); </code></pre> <p>I've tested this option successfully, but when you have the textfield at the bottom of the screen, this will move your stage bottom to the center of the screen, leaving a big gap between both stages (you'll see whatever you have on the background).</p> <p>I've managed to add a listener to the new stage and adjust the position just the necessary. If you are interested I could post it.</p> <p><strong>EDIT</strong></p> <p>Note this command line option won't work if the stage is maximized. A simple solution for this is:</p> <pre><code>Rectangle2D bounds = Screen.getPrimary().getBounds(); stage.setX(bounds.getMinX()); stage.setY(bounds.getMinY()); stage.setWidth(bounds.getWidth()); stage.setHeight(bounds.getHeight()); stage.show(); </code></pre> <br /><br /><br /><h3>回答3:</h3><br /><p>I liked the solution, but in my case I prefer to move the keyboard using the showed method <strong>getPopupWindow</strong> i created a listener on textfield and changed the position of the keyboard directly.</p> <pre><code>textField.focusedProperty().addListener((ob, b, b1) -&gt; { if (keyboard == null) { keyboard = getPopupWindow(); keyboard.setHideOnEscape(Boolean.TRUE); keyboard.setAutoHide(Boolean.TRUE); keyboard.centerOnScreen(); keyboard.requestFocus(); keyboard.sizeToScene(); } Platform.runLater(() -&gt; { keyboard.setY(**NEW_POSITION_OF_KEYBOARD**); }); }); </code></pre> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/27980788/javafx-virtual-keyboard-overlaps-nodes</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/java" hreflang="zh-hans">java</a></div> <div class="field--item"><a href="/tag/javafx-8" hreflang="zh-hans">javafx-8</a></div> <div class="field--item"><a href="/tag/virtual-keyboard" hreflang="zh-hans">virtual-keyboard</a></div> </div> </div> Fri, 03 Jan 2020 06:15:15 +0000 流过昼夜 3081110 at https://www.e-learn.cn VirtualKeyboard not Show when focus Edit fields in Firemonkey project https://www.e-learn.cn/topic/3020722 <span>VirtualKeyboard not Show when focus Edit fields in Firemonkey project</span> <span><span lang="" about="/user/174" typeof="schema:Person" property="schema:name" datatype="">旧街凉风</span></span> <span>2019-12-31 05:14:53</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I have a Firemonkey multi device project in Delphi 10 Seattle where the user can get a screen at the start of the app. Here the user needs to fill in 2 fields. But when I click on the edit fields the Virtual Keyboard isn't shown. If I skip this screen at start and call it later then the Virtual Keyboard is shown. This is done in the same way too.</p> <p>I found sort of a solution: When i click on the edit fields i call show VirtualKeyboard myself. The only problem is that the cursor isn't shown in the edit field.</p> <p>Is there a way to place the cursor myself? Or does anyone know how to solve the Virtual Keyboard not showing problem in an other way?</p> <p>Problem is on both Android and iOS</p> <p>In the code below you can see the initial form create. The problem is when in ConnectFromProfile method the actCreateNewProfileExecute is called. There it will call a new form. In that form(TfrmProfile) the virtual keyboard isn't shown. I also call this form with another action and then it works fine.</p> <pre><code>procedure TfrmNocoreDKS.FormCreate(Sender: TObject); begin Inherited; System.SysUtils.FormatSettings.ShortDateFormat := 'dd/mm/yyyy'; CheckPhone; ConnectfromProfile; if not Assigned(fProfileAction) then ConnectDatabase Else lstDocuments.Enabled := False; {$IFDEF ANDROID} ChangeComboBoxStyle; {$ENDIF} end; procedure TfrmNocoreDKS.ConnectfromProfile; begin fdmProfileConnection := TdmConnection.Create(nil); fdmProfileConnection.OpenProfileDb; fdmProfileConnection.LoadProfiles; if fdmProfileConnection.Profiles.Count = 0 then begin // Createdefault Profile fProfileAction := actCreateNewProfileExecute; end else if fdmProfileConnection.Profiles.Count = 1 then begin // one profile load connection; fProfileAction := nil; fCurrentProfile := fdmProfileConnection.Profiles.Items[0]; end else begin // multiple profiles choose connection; fProfileAction := SelectProfileOnStartUp; end; end; procedure TfrmNocoreDKS.FormShow(Sender: TObject); begin if Assigned(fProfileAction) then fProfileAction(Self); end; procedure TfrmNocoreDKS.actCreateNewProfileExecute(Sender: TObject); var profilename, databasename, pathname: string; prf: TfrmProfile; begin prf := TfrmProfile.Create(nil); prf.Data := fdmProfileConnection.Profiles; prf.ShowModal( procedure(ModalResult: TModalResult) begin if ModalResult = mrOk then begin profilename := prf.edtProfilename.Text; databasename := prf.edtDatabaseName.Text; {$IFDEF IOS} pathname := System.IOUtils.TPath.GetDocumentsPath; {$ENDIF} {$IFDEF ANDROID} pathname := System.IOUtils.TPath.GetDocumentsPath; {$ENDIF} {$IFDEF WIN32} pathname := ExtractFilePath(ParamStr(0)) + '\Data'; {$ENDIF} FDSQLiteBackup1.Database := System.IOUtils.TPath.Combine(pathname, 'default.sqlite3'); // Default Database FDSQLiteBackup1.DestDatabase := System.IOUtils.TPath.Combine(pathname, databasename + '.sqlite3'); FDSQLiteBackup1.Backup; fdmProfileConnection.AddProfile(databasename + '.sqlite3', profilename); fdmProfileConnection.LoadProfiles; fCurrentProfile := fdmProfileConnection.Profiles.Items[0]; connectDatabase; end else Application.Terminate; end); end; </code></pre> <br /><h3>回答1:</h3><br /><p>Do not show any additional forms in <code>MainForm.OnCreate/OnShow</code>. Trying this on iOS 9.2 freeze app at "launch screen".</p> <p>Instead of this, show new form asynchronously, like this:</p> <pre class="lang-pascal prettyprint-override"><code>procedure TForm4.FormShow(Sender: TObject); begin TTask.Run(procedure begin TThread.Synchronize(nil, procedure // work with visual controls - only throught Synchronize or Queue begin Form5:=TForm5.Create(Application); Form5.ShowModal; end) end); end; </code></pre> <p>of cource, you can separate this code to external procedures:</p> <pre class="lang-pascal prettyprint-override"><code>procedure ShowMyForm; begin Form5:=TForm5.Create(Application); Form5.ShowModal; end; procedure TaskProc; begin TThread.Synchronize(nil, ShowMyForm); end; procedure TForm4.FormShow(Sender: TObject); begin TTask.Run(TaskProc); end; </code></pre> <p>========</p> <p>Another way - do not use any additional forms. Create frame and put it (at runtime) on MainForm with <code>Align = Contents</code>. After all needed actions - hide or release (due to ARC dont forget to set nil to frame variable) this frame.</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/35272757/virtualkeyboard-not-show-when-focus-edit-fields-in-firemonkey-project</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/focus" hreflang="zh-hans">focus</a></div> <div class="field--item"><a href="/tag/edit" hreflang="zh-hans">edit</a></div> <div class="field--item"><a href="/tag/firemonkey" hreflang="zh-hans">firemonkey</a></div> <div class="field--item"><a href="/tag/virtual-keyboard" hreflang="zh-hans">virtual-keyboard</a></div> <div class="field--item"><a href="/tag/delphi-10-seattle" hreflang="zh-hans">delphi-10-seattle</a></div> </div> </div> Mon, 30 Dec 2019 21:14:53 +0000 旧街凉风 3020722 at https://www.e-learn.cn Java: Add a Global Mouse Listener https://www.e-learn.cn/topic/3017433 <span>Java: Add a Global Mouse Listener</span> <span><span lang="" about="/user/169" typeof="schema:Person" property="schema:name" datatype="">亡梦爱人</span></span> <span>2019-12-31 03:21:28</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I am developing a <strong>virtual keyboard</strong> using java applet. How do I set global mouse listener, so that I can get all mouse events inside my applet even if my applet is not the active window. And is there any way to get the focussed textbox globally, so that I can feed input to that textbox from my virtual keyboard. Thanks. </p> <br /><h3>回答1:</h3><br /><p>You need to make a hook for that you need native code for windows machine take a look here</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/4673061/java-add-a-global-mouse-listener</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/java" hreflang="zh-hans">java</a></div> <div class="field--item"><a href="/tag/listener" hreflang="zh-hans">listener</a></div> <div class="field--item"><a href="/tag/applet" hreflang="zh-hans">applet</a></div> <div class="field--item"><a href="/tag/virtual-keyboard" hreflang="zh-hans">virtual-keyboard</a></div> </div> </div> Mon, 30 Dec 2019 19:21:28 +0000 亡梦爱人 3017433 at https://www.e-learn.cn