I'm building a home surveillance system for use in my home and possibly to publish on my blog. However; I've ran into a problem. We only use a mouse for input, and most people use only mouse. So, I needed to build an on-screen keyboard. I got a VBA frame and put a text box, and layed out a load of buttons to make a keyboard. I need help with the code that makes it so that when you press a key it will put that character in the text input box so that the user can see what they are entering. If you know, or could suggest a fix, please reply! Thank you!
Asked
Active
Viewed 166 times
0
-
Why not just use the built-in windows on-screen keyboard? – omegastripes Aug 06 '18 at 19:00
-
Because that would be a pain to trigger, especially if running on a mac, I'd rather implement my own one that blends nicely, and I can add extra buttons for certain features – jj1064 Aug 06 '18 at 19:03
-
`Private Sub CommandButton1_Click(): Me.TextBox1.Value = Me.TextBox1.Value & "A": End Sub` – omegastripes Aug 06 '18 at 19:09
-
Works perfectly, great formatting by the way! Thank you very much! – jj1064 Aug 06 '18 at 19:24
-
I would suggest to create the buttons on the form dynamically within loop, and to create a class that will handle events from buttons clicks. – omegastripes Aug 06 '18 at 19:28
-
One question, how do I do the other controls like backspace (How do I remove characters from the textbox) – jj1064 Aug 06 '18 at 19:29
-
How would I do that please? Code? – jj1064 Aug 06 '18 at 19:37
-
For backspace use `If Not Len(Me.TextBox1.Value) = 0 Then Me.TextBox1.Value = Left(Me.TextBox1.Value, Len(Me.TextBox1.Value) - 1)` – omegastripes Aug 06 '18 at 19:38
-
Perfect! Only one more problem. How can I scroll through the textbox? I have a scrollbar (The two arrow buttons), could I use these to scrool the cursor through the input or do I program two seperate buttons? – jj1064 Aug 06 '18 at 19:43
-
Take a look e. g. [here](https://stackoverflow.com/a/48384652/2165759) and [here](https://stackoverflow.com/q/3014421/2165759) for creating controls dynamically and adding event handling. – omegastripes Aug 06 '18 at 19:54
-
Sorry but I'm scratching my head as VBA gives me errors whilst trying to configure this code. Could you give me some code I don't mind if it's for scroll bar buttons or two seperate buttons – jj1064 Aug 06 '18 at 19:57
-
Either set `TextBox` property `ScrollBars` to `1 - fmScrollBarsHorizontal`, or set property `TextAlign` to `3 - fmTextAlignRight` and add the line `Me.TextBox1.SetFocus` in each button click event handler. – omegastripes Aug 06 '18 at 20:07
-
Ok cheers. How do I get the text from the keyboard put into the username and password boxes? Would I have to add the box to the list on the buttons – jj1064 Aug 06 '18 at 20:28
-
For example: Me.currentkey.Value = Me.currentkey.Value , ADD HERE & "m" – jj1064 Aug 06 '18 at 20:29
-
To type text into multiply textboxes you need to 1) dim a private variable in userform module scope, 2) refer to it within each button click event handler (instead of hard coded `Me.TextBox1`), 3) and reference the variable to the textbox within each textbox enter event handler, and 3a) on userform initialization event. – omegastripes Aug 06 '18 at 22:32
-
I'm still confused... Could you give me some example code for the private variable? – jj1064 Aug 07 '18 at 08:20
-
`Private oCurrentTextBox As MSForms.TextBox` at the top of the userform module. – omegastripes Aug 07 '18 at 12:41