 | 
October 9th, 2008, 01:37 AM
| | Newbie | | Join Date: Oct 2008
Posts: 8
| | 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: - 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
-
- *****my tries: System.Windows.Forms.SendKeys.Send("{UP}") \\\\\\\\\ LeftButton_Click(Keys.Down, Keys.Down) *******
-
-
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 insertAlias; October 31st, 2008 at 10:13 PM.
Reason: added [CODE] [/CODE] tags
| 
October 9th, 2008, 10:00 AM
|  | Moderator | | Join Date: Dec 2006 Location: Northern Ireland / England Age: 24
Posts: 481
| |
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
| 
October 9th, 2008, 11:28 PM
| | Newbie | | Join Date: Oct 2008
Posts: 8
| | Quote: |
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.
| 
October 10th, 2008, 09:35 AM
|  | Moderator | | Join Date: Dec 2006 Location: Northern Ireland / England Age: 24
Posts: 481
| | Quote: |
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 selecteditemindex ++ 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
| 
October 10th, 2008, 08:01 PM
| | Newbie | | Join Date: Oct 2008
Posts: 8
| | Quote: |
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 selecteditemindex ++ 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....).
"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 selecteditemindex ++ 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.
| 
October 13th, 2008, 02:04 AM
| | Newbie | | Join Date: Oct 2008
Posts: 8
| |
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
| 
October 16th, 2008, 05:36 AM
| | Newbie | | Join Date: Oct 2008
Posts: 1
| |
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 selecteditemindex ++ 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?
| 
October 31st, 2008, 07:04 AM
| | Newbie | | Join Date: Oct 2008
Posts: 5
| |
hey already explained you dude i think it will help you out
| 
October 31st, 2008, 10:29 AM
|  | Moderator | | Join Date: Dec 2006 Location: Northern Ireland / England Age: 24
Posts: 481
| | Quote: |
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("Coredll.dll", SetLastError = true)]
static extern int keybd_event(byte 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
| 
October 31st, 2008, 01:32 PM
| | Newbie | | Join Date: Oct 2008
Posts: 8
| | Quote: |
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
| 
October 31st, 2008, 03:49 PM
| | Newbie | | Join Date: Oct 2008
Posts: 8
| |
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? - 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 insertAlias; October 31st, 2008 at 10:15 PM.
Reason: added [CODE] [/CODE] tags
| 
October 31st, 2008, 10:16 PM
|  | Moderator | | Join Date: Apr 2008 Location: San Antonio, TX (USA) Age: 24
Posts: 1,936
| |
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
| 
November 1st, 2008, 06:43 AM
| | Newbie | | Join Date: Oct 2008
Posts: 5
| |
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
| 
November 1st, 2008, 12:34 PM
| | Newbie | | Join Date: Oct 2008
Posts: 8
| |
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: - 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
| 
November 3rd, 2008, 07:38 AM
|  | Moderator | | Join Date: Dec 2006 Location: Northern Ireland / England Age: 24
Posts: 481
| |
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.
| 
November 3rd, 2008, 10:18 AM
| | Newbie | | Join Date: Oct 2008
Posts: 8
| | Quote: |
Originally Posted by markmcgookin 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. | Tanks for the tip.
I will try to find something in SIP panel programing code.
I think it will be a little bit tricky...But I will try.
If you have any other tips for how to, just let me know.
Tanks
|  |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | | | | What is Bytes?
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over network members.
|