Make application buttons assign to keys up, down, left, right...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ImpactMan
    New Member
    • Oct 2008
    • 9

    Make application buttons assign to keys up, down, left, right...

    Need help to create an windows mobile application with a few buttons that when they are pressed/clicked they assign keys, like up, down, left, right.

    It is just like to create a "virtual d-pad", or "software emulated d-pad".

    I'm newbie in programming, and I'm using Visual Studio 2008.
    Some one can help me with that?

    Tanks.

    My effort for it only result in this simple code lines:

    Code:
    Public Class Form1
    
        Private Sub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitButton.Click
    
            'Bye!
    
            Application.Exit()
    
        End Sub
    
        Private Sub UpButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UpButton.Click
    
            'Up
    
    [I]  *****my tries:      System.Windows.Forms.SendKeys.Send("{UP}") \\\\\\\\\ LeftButton_Click(Keys.Down, Keys.Down)     *******[/I]
    
        End Sub
    
        Private Sub LeftButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LeftButton.Click
    
            'Left
    
           
    
        End Sub
    
        Private Sub DownButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DownButton.Click
    
            'Down
    
    
    
        End Sub
    
        Private Sub RightButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RightButton.Click
    
            'Right
    
    
    
        End Sub
    End Class
    Last edited by Curtis Rutland; Oct 31 '08, 09:13 PM. Reason: added [CODE] [/CODE] tags
  • markmcgookin
    Recognized Expert Contributor
    • Dec 2006
    • 648

    #2
    Hi,

    Welcome to Bytes! Can I just clarify what you are after here?

    So you have a device/emulator and you want 4 buttons on the screen to emulate what the "dpad" directional buttons already do? or do you simply want to create four buttons from scratch?

    Either way in VS2008 this is nice and easy. Just drag four buttons onto the form, then click properties on each button, then if you already have an action on the "dpad" or softkeys as we call them you can just click the little lightning symbol at the top and find the on click event and use the drop down menu to select the same action that your soft key has... so binding the "on press" event to the same thing.

    Otherwise if you just want this to be a function in it's own right, just double click on the button, and enter your code.

    I'm not sure if this is what you are after, but if you have any more questions, please be a bit more specific.

    Thanks,

    Mark

    Comment

    • ImpactMan
      New Member
      • Oct 2008
      • 9

      #3
      Originally posted by markmcgookin
      Hi,

      Welcome to Bytes! Can I just clarify what you are after here?

      So you have a device/emulator and you want 4 buttons on the screen to emulate what the "dpad" directional buttons already do? or do you simply want to create four buttons from scratch?

      Either way in VS2008 this is nice and easy. Just drag four buttons onto the form, then click properties on each button, then if you already have an action on the "dpad" or softkeys as we call them you can just click the little lightning symbol at the top and find the on click event and use the drop down menu to select the same action that your soft key has... so binding the "on press" event to the same thing.

      Otherwise if you just want this to be a function in it's own right, just double click on the button, and enter your code.

      I'm not sure if this is what you are after, but if you have any more questions, please be a bit more specific.

      Thanks,

      Mark


      Hello.

      Tanks for the answer and sorry about my english, maybe not much specific. I'm Portuguese.

      I try to explain specifically what I want.

      I have a Pocket PC device each don't have a dpad.

      So, I'm trying to emulate/replicate the normal pocket pc dpad hardware.

      I want to do one application with 4 buttons on the screen to emulate what the "dpad" directional buttons do.

      I've already create those buttons with visual studio (I've placed 4 images to work as buttons. I think this is possible.)

      Now, my problem is to assign functions/acctions to this buttons each makes the same as the dpad. Not getting any results. :(

      If you can tell me some tips or If you can show me an example for one button, I will be tankful.

      Kind regards.

      Comment

      • markmcgookin
        Recognized Expert Contributor
        • Dec 2006
        • 648

        #4
        Originally posted by ImpactMan
        Hello.

        Tanks for the answer and sorry about my english, maybe not much specific. I'm Portuguese.

        I try to explain specifically what I want.

        I have a Pocket PC device each don't have a dpad.

        So, I'm trying to emulate/replicate the normal pocket pc dpad hardware.

        I want to do one application with 4 buttons on the screen to emulate what the "dpad" directional buttons do.

        I've already create those buttons with visual studio (I've placed 4 images to work as buttons. I think this is possible.)

        Now, my problem is to assign functions/acctions to this buttons each makes the same as the dpad. Not getting any results. :(

        If you can tell me some tips or If you can show me an example for one button, I will be tankful.

        Kind regards.
        Right, so you have dragged a .Net Picture box onto the form?

        Unfortunatley I dont think there is any automatic way to replace all the functions of the soft keys, but you can code them yourself (to move inbetween items, it's selecteditemind ex ++ or -- etc. Have you managed to get anything to happen when you click the image? or is that your problem? or is your problem that you have it doing things, you just can't replicate the functions of the soft keys?

        To make an image clickable, you need to select it, right click > properties > click on the little lightning icon in the properties tab > then double click in the box beside "Click" and this will create an event handler (and should take you to it in the code) for the click event on the button.

        Mark

        Comment

        • ImpactMan
          New Member
          • Oct 2008
          • 9

          #5
          Originally posted by markmcgookin
          Right, so you have dragged a .Net Picture box onto the form?

          Unfortunatley I dont think there is any automatic way to replace all the functions of the soft keys, but you can code them yourself (to move inbetween items, it's selecteditemind ex ++ or -- etc. Have you managed to get anything to happen when you click the image? or is that your problem? or is your problem that you have it doing things, you just can't replicate the functions of the soft keys?

          To make an image clickable, you need to select it, right click > properties > click on the little lightning icon in the properties tab > then double click in the box beside "Click" and this will create an event handler (and should take you to it in the code) for the click event on the button.

          Mark

          Tanks.
          I think I've already make images clickable.
          But, maybe it will get me some more troubles. Do you think is better to start with simple buttons?

          Doing this with simple buttons, the same way, I can't add an action to button that replicates/simulates the dpad (keys up, down....).

          "Unfortunat ley I dont think there is any automatic way to replace all the functions of the soft keys, but you can code them yourself (to move inbetween items, it's selecteditemind ex ++ or -- etc."

          I would like to try it now, but I'm on my PC with VS only Monday.
          Anyway, if you can show-me some code lines example to do this, it will make me understanding the program structure and the basics for doing that.

          Tanks for all your availability.

          Best regardes.

          Filipe



          Kind regards.

          Comment

          • ImpactMan
            New Member
            • Oct 2008
            • 9

            #6
            Hi!

            I've been trying to make this work, but, not getting any results. :(

            I don't know more what to do or how to proceed!

            The only button (which is an image) that I can make work is the one to close the application. Not a progress at all!

            I tink I have to see some examples do perform my program.

            If you have time, and if you can, you could show me some code lines.
            I will appreciate that.

            Tanks.

            Filipe

            Comment

            • Mokbol

              #7
              I dont think there is any automatic way to replace all the functions of the soft keys, but you can code them yourself (to move inbetween items, it's selecteditemind ex ++ or -- etc. Have you managed to get anything to happen when you click the image? or is that your problem? or is your problem that you have it doing things, you just can't replicate the functions of the soft keys?

              Comment

              • rahulsengar
                New Member
                • Oct 2008
                • 6

                #8
                hey already explained you dude i think it will help you out

                Comment

                • markmcgookin
                  Recognized Expert Contributor
                  • Dec 2006
                  • 648

                  #9
                  Originally posted by rahulsengar
                  Rahul Says:

                  You can do something like this to make it work.

                  Add the dll - System.runtime. IneropServices
                  then add this code where you initialize all the global variables
                  [DllImport("Core dll.dll", SetLastError = true)]
                  static extern int keybd_event(byt e b, byte b1, int dwflags, int dwExtraInfo);

                  1) On menuclick1-
                  add this set of code when u want the display to move up
                  keybd_event(38, 0, 0, 0); //
                  keybd_event(38, 0, 2, 0); //this code Works similarly when u press up
                  2) On menuclick2 -
                  add this set of code when u want the display to move down
                  keybd_event(40, 0, 0, 0);
                  keybd_event(40, 0, 2, 0);
                  I have posted the above quote as it was in another thread... IMPACTMAN ... You have been warned before about this DO NOT DOUBLE POST, this is your last warning.

                  I will remove the other thread.

                  Mark

                  Comment

                  • ImpactMan
                    New Member
                    • Oct 2008
                    • 9

                    #10
                    Originally posted by markmcgookin
                    I have posted the above quote as it was in another thread... IMPACTMAN ... You have been warned before about this DO NOT DOUBLE POST, this is your last warning.

                    I will remove the other thread.

                    Mark

                    Hi there!

                    Sorry about it. I don't was't seen this post, and today I make the same mistake!! Posting again other topic with the same subject.
                    If you can remove it to me, I will be glad. Tanks for the info and for the help.

                    Regards.

                    Filipe

                    Comment

                    • ImpactMan
                      New Member
                      • Oct 2008
                      • 9

                      #11
                      Hello again!
                      I've been all morning trying to make this working.
                      I think now I have something "near" to working.
                      Can you take a look of the code and tell-me if it is ok?

                      Code:
                      Imports System
                      Imports System.Runtime.InteropServices
                      
                      Public Class Form1
                          <DllImport("coredll.dll", CallingConvention:=CallingConvention.Winapi, CharSet:=CharSet.Unicode, EntryPoint:="keybd_event", SetLastError:=True)> _
                          Public Shared Sub keybd_event(ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Integer, ByVal dwExtraInfo As Integer)
                          End Sub
                          Private Sub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitButton.Click
                              'Bye!
                              Application.Exit()
                          End Sub
                      
                          Private Sub UpButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UpButton.Click
                              'Up
                              keybd_event(26, 0, 0, 0)
                          End Sub
                      
                          Private Sub LeftButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LeftButton.Click
                              'Left
                              keybd_event(25, 0, 0, 0)
                          End Sub
                      
                          Private Sub DownButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DownButton.Click
                              'Down
                              keybd_event(28, 0, 0, 0)
                          End Sub
                      
                          Private Sub RightButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RightButton.Click
                              'Right
                              keybd_event(27, 0, 0, 0)
                          End Sub
                      End Class
                      Now I have other problem, that I don't know if it is possible or not to do.
                      Do you think is possible to make the buttons application work when one other application is running on the top of buttons application?
                      For example, windows explorer, or other full screen application is running and buttons application steal being able to control it, just like we have hardware buttons.
                      Is more alike one application that "mapping the screen" and can control all other applications like if we have hardware keys.


                      If some one have any tips for help, I will be tankful.

                      Tanks to all.

                      Regards.
                      Last edited by Curtis Rutland; Oct 31 '08, 09:15 PM. Reason: added [CODE] [/CODE] tags

                      Comment

                      • Curtis Rutland
                        Recognized Expert Specialist
                        • Apr 2008
                        • 3264

                        #12
                        Please enclose your posted code in [CODE] [/CODE] tags (See How to Ask a Question).

                        This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

                        Please use [CODE] [/CODE] tags in future.

                        MODERATOR

                        Comment

                        • rahulsengar
                          New Member
                          • Oct 2008
                          • 6

                          #13
                          hey rahul sengar says:

                          Actually what you did is correct
                          but when you are raising key board events it should have proper meaning which you not following i believe

                          the value for clicking the button up is 40
                          and the value for clicking down is 38
                          better you go for this

                          wright in google search
                          key code in windows mobile ( i am sure you will get the values in hexadecimal and convert it as integer type )
                          and set the value for a particular event

                          Comment

                          • ImpactMan
                            New Member
                            • Oct 2008
                            • 9

                            #14
                            Hello!

                            Tanks for the tip. I search on goolge and find Keys and Key Codes for Win Mobile and try to adapt the code to it.

                            Here is the changes:

                            Code:
                                    Private Sub UpButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UpButton.Click
                                    Const VK_UP As Byte = &H26
                                    keybd_event(VK_UP, 0, 0, 0)
                                    'Up
                                End Sub
                            
                                Private Sub LeftButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LeftButton.Click
                                    Const VK_LEFT As Byte = &H25
                                    keybd_event(VK_LEFT, 0, 0, 0)
                                    'Left
                                End Sub
                            Do you think this now will work?
                            For test it I need now to make the buttons application run even when any other application is running and try to control it with this "virtual buttons", but I don“t know if it's possible!?
                            For example, is it possible to move between items on "windows mob. file explorer" using the up and down keys of buttons application?

                            When I try to do it, the buttons application came to the "top" and windows file explorer control seems to be disable.

                            Tanks for your help.

                            Regards

                            Filipe

                            Comment

                            • markmcgookin
                              Recognized Expert Contributor
                              • Dec 2006
                              • 648

                              #15
                              You won't be able to run one on top of another like that, if you are looking to control other applications, you really need to be looking into creating a custom SIP panel with some kind of arrow keys maby.

                              Comment

                              Working...