AdvancedHMI Software

General Category => Open Discussion => Topic started by: carlthesparky on December 07, 2016, 03:37:28 AM

Title: Key board control
Post by: carlthesparky on December 07, 2016, 03:37:28 AM
is their a way to press a push button or a basic button by using a key on the keyboard?
Title: Re: Key board control
Post by: Archie on December 07, 2016, 05:50:33 AM
In the Text property of a button, insert an "&" before the keyboard letter you want to use. For example "Start &Motor". When you run the program, you can use Alt-M to click that button.
Title: Re: Key board control
Post by: carlthesparky on December 07, 2016, 06:15:28 AM
Does not seem to work.... Lets say in the text property I say ''&S'' then I should be able to type Alt S and should be working?
Title: Re: Key board control
Post by: Archie on December 07, 2016, 06:34:28 AM
Does not seem to work.... Lets say in the text property I say ''&S'' then I should be able to type Alt S and should be working?
Yes. Try this:

- Add a BasicButton to the form
- Change the Text property to "&BasicButton1"
- Double click the button to get back to the code
- Enter this code:

 MsgBox("Button clicked!")

- Run the application and press Alt-B on the keyboard
Title: Re: Key board control
Post by: Archie on December 07, 2016, 06:46:12 AM
I just thought about it and this will probably not work when controlling the PLC because the Alt-B action clicks the button, but the PLC writing is activated by Mouse Down and Mouse Up events.

Another option that may work is to Tab through the controls to get the button highlighted that you want to click , then press Enter.

Or you could write to the PLC via code in the Click event handler. In the example above, instead of using the MsgBox, you would use something like this:

EthernetIPforCLXCom1.Write("MyButtonTag","1")
Title: Re: Key board control
Post by: carlthesparky on December 07, 2016, 06:51:38 AM
I will try option 3 but in my case im using comdf1 will that still work?
Title: Re: Key board control
Post by: carlthesparky on December 07, 2016, 06:55:53 AM
Oh and please show me where in the code I must make these changes im am a noob at code
Title: Re: Key board control
Post by: Archie on December 07, 2016, 07:09:52 AM
- Add a BasicButton to the form
- Change the Text property to "&BasicButton1"
- Double click the button to get back to the code
- Enter this code:

 EthernetIPforCLXCom1.Write("MyButtonTag","1")

- Run the application and press Alt-B on the keyboard

Keep in mind this will only set your PLC bit to true. You will need another mechanism to clear the bit, such as logic in the PLC
Title: Re: Key board control
Post by: carlthesparky on December 07, 2016, 08:24:03 AM
Ok I copy and pasted the code then I get a build error hahaha im sorry being a pain
Title: Re: Key board control
Post by: Archie on December 07, 2016, 08:26:24 AM
What driver are you using?
Title: Re: Key board control
Post by: carlthesparky on December 07, 2016, 08:30:55 AM
SerialDf1forSLCMicrocom1
Title: Re: Key board control
Post by: Archie on December 07, 2016, 08:39:10 AM
SerialDf1forSLCMicrocom1.write("B3/0","1")
Title: Re: Key board control
Post by: carlthesparky on December 07, 2016, 08:44:03 AM
[
Title: Re: Key board control
Post by: Archie on December 07, 2016, 09:33:14 AM
Show a screen shot of your MainForm so I can see the exact name of your driver.
Title: Re: Key board control
Post by: carlthesparky on December 08, 2016, 12:13:44 AM
Ok here it is
Title: Re: Key board control
Post by: carlthesparky on December 08, 2016, 12:15:03 AM
then I got the code to stay without error but when I test it this happens not sure what this means
Title: Re: Key board control
Post by: Archie on December 08, 2016, 12:47:06 AM
It looks correct to me. Instead of copy and paste, if you start typing the line of code, will Intellisense start completing the code for you or give you an option to select?
Title: Re: Key board control
Post by: carlthesparky on December 08, 2016, 01:01:11 AM
ok so I did that but I still get this error
Title: Re: Key board control
Post by: Archie on December 08, 2016, 01:10:55 AM
Are you using RSEmulate?
Title: Re: Key board control
Post by: carlthesparky on December 08, 2016, 01:26:51 AM
I am indeed using rs emulate
Title: Re: Key board control
Post by: Archie on December 08, 2016, 01:32:46 AM
I don't have any experience with RSEmulate, so I can't offer any help with it. Maybe someone else will chime in that has used RSEmulate.
Title: Re: Key board control
Post by: carlthesparky on December 08, 2016, 02:18:28 AM
ok great thanks for all you help so far....
Title: Re: Key board control
Post by: carlthesparky on December 08, 2016, 08:26:55 AM
hey sorry its me again I tried that code for Ethernet driver not connected to emulate or any other plc and I still get this error .any thoughts?
Title: Re: Key board control
Post by: carlthesparky on December 08, 2016, 08:28:36 AM
sorry here is that error
Title: Re: Key board control
Post by: Godra on December 08, 2016, 09:48:21 AM
Before you started this topic and asked the question, was your program working OK and communicating with RS Emulate?

Also, take a look at Archie's reply #16:

It looks correct to me. Instead of copy and paste, if you start typing the line of code, will Intellisense start completing the code for you or give you an option to select?

In the pictures you posted, Intellisense doesn't seem to be working since it should have changed "com1" to "Com1" at the end of your driver name.

Look at the very first post here to see how to make changes:

https://www.google.ca/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=visual+studio+turn+on+intellisense

Also change the code from:

   SerialDf1forSLCMicrocom1.write("B3/0","1")
to:
   SerialDf1forSLCMicroCom1.write("B3:0/0", "1")


EthernetIPforCLX driver was suggested only as an example. It cannot communicate with RSLogix Emulate 500.
Title: Re: Key board control
Post by: Godra on December 08, 2016, 10:36:45 PM
Another possible approach to assign keyboard shortcuts for different events could be done within the form's KeyUp event:

Code: [Select]
    Private Sub MainForm_KeyUp(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
        If (e.Shift AndAlso e.KeyCode = Keys.A) Then ' SHIFT+A keys combination --> Write "1" to B3:0/0
            SerialDF1forSLCMicroCom1.Write("B3:0/0", "1")
        ElseIf (e.Shift AndAlso e.KeyCode = Keys.B) Then ' SHIFT+B keys combination --> Write "0" to B3:0/0
            SerialDF1forSLCMicroCom1.Write("B3:0/0", "0")
        ElseIf (e.Shift AndAlso e.KeyCode = Keys.C) Then ' SHIFT+C keys combination --> Open Calculator
            System.Diagnostics.Process.Start("calc.exe")
        End If
    End Sub

This approach doesn't require a control to be present on the form.
Title: Re: Key board control
Post by: carlthesparky on December 09, 2016, 01:20:47 AM
hi thanks for all the input ive put in the new code and typed it in as said and not just copy pasted it and the button works when I click but not when I use the key board so my new quesrion is would I still put the address in the click address or where would I put it for the key board to write ?
Title: Re: Key board control
Post by: Godra on December 09, 2016, 10:19:03 AM
You should try to use the whole code from my previous post, just copy and paste it.
Once you run the program, see if you get any errors and if not then try all 3 combinations of keys one at the time (SHIFT+A, SHIFT+B, SHIFT+C).

This is what you should know in general:

- PLCAddressClick field of the BasicButton should have address like B3:0/0
- Text field of the BasicButton can have any text in it. If you put "&" before any specific letter or number then that letter/number can be used together with ALT key on the keyboard to perform Click.
- When using the code to perform write then you have to use format like SerialDf1forSLCMicroCom1.write("B3:0/0", "1"). This line of code needs to be placed inside a sub (just like Archie explained it in previous posts).