Trapping Hardware buttons - Windows Mobile Development and Hacking General

Hi,
anyone know how, or if it is possible to trap the green 'call' button on the xda ii. I can trap the camera, voice recorder and top 2 buttons, but i need to trap the call button
Thanks
Pete

use GetAsyncKeyState

Hi,
tried trapping it in a timer with getasynckeystate , but only seem to pick up the 'd' pad, not any of the other keys.
Using registerhotkey for the other 4 which works fine, just not for the call button
Thanks
Pete

Could you please let me know how you could trap the camera and the two top buttons.
Could you also trap the Red button ?
Many Thanks

Hi,
Paste the following code into a module, and call in in the form_load as follows:-
Dim messageWindow As Hwbuttons.hwMessageWindow
Me.messageWindow = New Hwbuttons.hwMessageWindow(Me)
RegisterHKeys.RegisterRecordKey(Me.messageWindow.Hwnd)
The original code for this comes from www.opennetcf.org - I modified it for my needs, so kudos to the original poster(s).
I have still not found a way to trap the 'green and red' keys
Pete
Imports Microsoft.WindowsCE.Forms
Imports System.Runtime.InteropServices
Public Enum KeyModifiers As Integer
None = 0
Alt = 1
Control = 2
Shift = 4
Windows = 8
Modkeyup = &H1000
End Enum
Public Enum KeysHardware As Integer
Hardware1 = 193
Hardware2 = 194
Hardware3 = 195
Hardware4 = 196
Hardware5 = 202
End Enum
Public Module RegisterHKeys
<DllImport("coredll.dll", Entrypoint:="RegisterHotKey", setLastError:=True)> _
Public Function RegisterHotKey( _
ByVal hWnd As IntPtr, _
ByVal id As Integer, _
ByVal Modifiers As KeyModifiers, _
ByVal key As Integer) As Boolean
End Function
<DllImport("coredll.dll")> _
Private Function UnregisterFunc1( _
ByVal modifiers As KeyModifiers, _
ByVal keyID As Integer) As Boolean
End Function
Public Sub RegisterRecordKey(ByVal hWnd As IntPtr)
UnregisterFunc1(KeyModifiers.Windows, CType(KeysHardware.Hardware1, Integer))
RegisterHotKey(hWnd, CType(KeysHardware.Hardware1, Integer), KeyModifiers.Windows, CType(KeysHardware.Hardware1, Integer))
UnregisterFunc1(KeyModifiers.Windows, CType(KeysHardware.Hardware2, Integer))
RegisterHotKey(hWnd, CType(KeysHardware.Hardware2, Integer), KeyModifiers.Windows, CType(KeysHardware.Hardware2, Integer))
UnregisterFunc1(KeyModifiers.Windows, CType(KeysHardware.Hardware3, Integer))
RegisterHotKey(hWnd, CType(KeysHardware.Hardware3, Integer), KeyModifiers.Windows, CType(KeysHardware.Hardware3, Integer))
UnregisterFunc1(KeyModifiers.Windows, CType(KeysHardware.Hardware4, Integer))
RegisterHotKey(hWnd, CType(KeysHardware.Hardware4, Integer), KeyModifiers.Windows, CType(KeysHardware.Hardware4, Integer))
UnregisterFunc1(KeyModifiers.Windows, CType(KeysHardware.Hardware5, Integer))
RegisterHotKey(hWnd, CType(KeysHardware.Hardware5, Integer), KeyModifiers.Windows, CType(KeysHardware.Hardware5, Integer))
End Sub
Public Class Hwbuttons
Inherits System.Windows.Forms.Form
Public Shared messageWindow As hwMessageWindow
Public Class hwMessageWindow
Inherits messageWindow
Public Const WM_HOTKEY = &H312
Dim example As frmComms
Public Sub New(ByVal example As frmComms)
Me.example = example
End Sub
Protected Overrides Sub WndProc(ByRef msg As Message)
Select Case msg.Msg
Case WM_HOTKEY
'ButtonPressed(msg.WParam.ToInt32())
Return
End Select
MyBase.WndProc(msg)
End Sub
Public Sub ButtonPressed(ByVal button As Integer)
Select Case button
Case KeysHardware.Hardware1
MessageBox.Show("Button 1 pressed!")
Exit Sub
Case KeysHardware.Hardware2
MessageBox.Show("Button 2 pressed!")
Exit Sub
Case KeysHardware.Hardware3
MessageBox.Show("Button 3 pressed!")
Exit Sub
Case KeysHardware.Hardware4
MessageBox.Show("Button 4 pressed!")
Exit Sub
Case KeysHardware.Hardware5
MessageBox.Show("Button 5 pressed!")
Exit Sub
End Select
End Sub
End Class
End Class
End Module

Many Thanks.
I will give it a go.
Please let me know if you could find a way to control the Green and Red Buttons.
Thanks Again
:lol:

the green+red keys are already registered to the cprog.exe phone app.
you can grab them, by killing cprog.exe and then registering them.
this will prevent the original phone app from starting up.
( it is automatically restarted every minute orso, by shell32.exe )

Hi,
thanks for that - but using PHM task manager I am unable to stop the process from running.
I will take the 'o2active' from the startup and generally poke around to see if i can get it to stop
Thanks
Pete

I mean you should stop it from your own program, using 'TerminateProcess'
see http://www.xs4all.nl/~itsme/projects/xda/tools.html itsutils.cpp
for how to use TerminateProcess

Hi,
thanks - pkill does terminate the process - I thought PHM task manager would work using 'end process' but it does not.
Right - when I kill it, I then start 'button finder' to trap the hardware buttons, but as soon as I hit the green button, cprog relaunches
Thanks for your help
Pete

you should program it your self:
Code:
#define VK_ANSWER 0x72
#define VK_HANGUP 0x73
TerminateProcess(...); // kill cprog.exe
RegisterHotKey(..., 1, 0, VK_ANSWER); // steal hotkey
RegisterHotKey(..., 1, 0, VK_HANGUP); // steal hotkey

Isn't there some win32 way to "steal" messages from another application? If you can do that, you could steal the WM_HOTKEY message from the phone app, that way, you wouldn't have to kill it. I am not sure if killing it would cause you to miss calls or not.

Has anyone posted a clear solution
I have been searching all over the net for a clear solution on hhow to trap these hardware keys and I just can't find anything. Does anyone have a nice clear solution yet?
I have to get the green call key and the red hang up key.
thanks,
Dan

Re: Has anyone posted a clear solution
I've seen several games that intercept "call" and "hang" buttons using GAPI. I have not tested this myself, but you can try.

You can unregister and register the buttons to your own app without killing the phone process, using the same functions as the code pete posted:-
UnregisterFunc1(KeyModifiers.None, CType(KeysHardware.Answer, Integer))
RegisterHotKey(hWnd, CType(KeysHardware.Answer, Integer), KeyModifiers.None, CType(KeysHardware.Answer, Integer))
UnregisterFunc1(KeyModifiers.None, CType(KeysHardware.Hangup, Integer))
RegisterHotKey(hWnd, CType(KeysHardware.Hangup, Integer), KeyModifiers.None, CType(KeysHardware.Hangup, Integer))
Where KeysHardware.Answer = &H72 and KeysHardware.Hangup = &h73
The difference between these two keys and the other hardware keys is they are not sent with the Windows key modifier.
Peter

sorry to bring back this old post, i have tried the code in this thread and successfully capture the green button, but after my application quit how can i restore back the button original function? anyone can help?

Related

little coding help needed

hey folks,
here's what I wanna do:
I need a program that runs in the background and checks if my mda2 is in the cradle or not. if it's plugged in the cradle I want it to change in my connection settings from work to internet. I need this for the following reason: my cellphone provider only offers grps over a proxy and that proxy wount work in the cralde when I share my PC connection via active sync. so right now I always need to switch between work and internet connection by myself.
I only know visual basic so I guess I need to take a look at eVB.
Is such a tool even possible in eVB? if so, where would I start? can someone point me in the right direction? maybe give me some links for research.
thanks for your help in advance
cyas
ait, did some research.
looks like just turning the proxy off should do the trick.
I tried doing this via the registry.
for now I just wanted to read out a key. this is what I got so far:
Code:
Option Explicit
Public Declare Function RegOpenKeyEx Lib "Coredll" Alias "RegOpenKeyExW" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Public Declare Function RegQueryValueEx Lib "Coredll" Alias "RegQueryValueExW" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, ByVal lpData As String, lpcbData As Long) As Long
Public Declare Function RegCloseKey Lib "Coredll" (ByVal hKey As Long) As Long
Const ERROR_SUCCESS = &O0
Const HKEY_LOCAL_MACHINE = &H80000001
Private Sub Command1_Click()
Dim lngSize As Long, hlngSubKey As Long
Dim lngType As Long, lngResult As Long
Dim RegData As Integer
lngSize = 256
RegData = String(lngSize, 0)
lngResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "\SOFTWARE\Microsoft\ConnMgr\Providers\{EF097F4C-DC4B-4c98-8FF6-AEF805DC0E8E}\HTTP-{18AD9FBD-F716-ACB6-FD8A-1965DB95B814}", 0, 0, hlngSubKey)
lngResult = RegQueryValueEx(hlngSubKey, "Proxy", 0, lngType, RegData, lngSize)
MsgBox RegData, vbOKOnly, "o2 proxy"
lngResult = RegCloseKey(hlngSubKey)
End Sub
Private Sub Form_OKClick()
App.End
End Sub
unfortunately when I press the button I only get a blank window. it wount show the proxy.
can someone tell me what I'm doing wrong?
oh and I still dont know how I could detect wether there is an active sync connection open or not. any ideas on that?
uhm, no one here who knows some eVB?
_4saken_ said:
Dim RegData As Integer
Click to expand...
Click to collapse
RegData should be declared as
Code:
Dim RegData As String
thanks for the answer but changing it to string didnt help. I still get an empty msg box.
any other ideas what I'm doing wrong?

Simulate Button Click

Hi,
I am trying to simulate a PictureBox.Click event. I have searched these forums and the ones on MSDN with many different combinations of search terms.
However I cannot find anything!
Basically what I am trying to achieve is to fire the picturebox's click event from within my code. What I have read so far seems to indicate that I need to make a call to SendMessage (COM interop?) to actually make windows perform the click.
This is for the compact framework version 1.0.
Any help you can give would be great because this is all very new to me, I'm a web application developer by trade so i'm a fish out of water on this one!
OK, the other method that I am investigating is the use of the mouse_event as demonstrated in this article by Daniel Moth.
However I am struggling to find the namespace Win32Api anywhere in the framework so I'm struggling with that also.
*Update*
I have been able to simulate a click using mouse_event in a call to the coredll using the following code:
Code:
[DllImport("coredll")]
static extern bool SetCursorPos(int X, int Y);
[DllImport("coredll")]
static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint dwData, int dwExtraInfo);
[Flags]
public enum MouseEventFlags
{
LEFTDOWN = 0x00000002,
LEFTUP = 0x00000004,
MIDDLEDOWN = 0x00000020,
MIDDLEUP = 0x00000040,
MOVE = 0x00000001,
ABSOLUTE = 0x00008000,
RIGHTDOWN = 0x00000008,
RIGHTUP = 0x00000010
}
bool tempVal = SetCursorPos(x, y);
mouse_event((uint)MouseEventFlags.LEFTDOWN, 0, 0, 0, 0);
mouse_event((uint)MouseEventFlags.LEFTUP, 0, 0, 0, 0);
however I have one outstanding problem (that I know of!).
I am struggling to capture the corrext X and Y co-ordinates of the control. I have tried many different methods and they all return values of 0 for both axis.
How do you guys do it?
Many Thanks
I haven't answered till now since I don't know .NET
But since you found your way to using native APIs I think I can help you.
This is how I would do it in C/C++:
Code:
RECT wndRect; //this is a structure that contains window top, left, bottom and right coordinates.
GetWindowRect(FindWind(L"[I]window class[/I]", L"[I]window name[/I]"), &wndRect);
x = wndRect.left + 1; //add 1 to window position to make sure the click is inside
y = wndRect.top + 1;
GetWindowRect returns the window position in screen coordinates for top left and bottom right corners.
For FindWindow to work you need to know the class and name of the window you want to find. You can find them using a utility called SPY++ which comes with any Microsoft C++ compiler.
The class is window type (so it will probably be something like 'PictureBox' or 'Image') and window name is most likely blank.
Hope this helps.
Thanks fo your help
I don't know if your code would have done the trick or not but I managed to work my way through the different class definitions to find what i needed.
Code:
int x = selectedButton.PointToScreen(selectedButton.Bounds.Location).X + 2;
int y = selectedButton.PointToScreen(selectedButton.Bounds.Location).Y + 2;
This still doesn't work but I really don't have time to work out why, all I know is that the call to SetCursorPos() returns false. I know the mouse_event code works because if I position the cursor over the Start button it opens the menu.
Time is of an essence so for now I'm just going to have to drop this and pray that I have time to finish this when towards the end of my project.
/me thinks writing my first Mobile 5.0 application in 4 days (I'm a web application developer by trade) was bad planning on the management's fault anyway
Thanks for your input though
use this method signature:
[DllImport("coredll")]
public static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo);
int instead of uint or long.
For me it worked.

Problem creating Registry Keys - VB.NET CF 1.x

Hi, if i create a registry key i get an NonSupportet Exception.
Can someone Help?
Here the important part of my code:
Code:
Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const KEY_ALL_ACCESS = &H3F
Public Const REG_OPTION_NON_VOLATILE = 0
Private Declare Function RegCreateKeyEx Lib "coredll.dll" Alias "RegCreateKeyExW" ( _
ByVal hkey As Long, _
ByVal lpSubKey As String, _
ByVal Reserved As Long, _
ByVal lpClass As String, _
ByVal dwOptions As Long, _
ByVal samDesired As Long, _
ByVal lpSecurityAttributes As Long, _
ByRef phkResult As Long, _
ByRef lpdwDisposition As Long) As Long
Public Shared Function CreateNewKey(ByVal lSection As Long, _
ByVal sNewKeyName As String) As Long
Dim hNewKey As Long
Dim lRetVal As Long
RegCloseKey(lSection)
--HERE--> lRetVal = RegCreateKeyEx(lSection, sNewKeyName, 0, _
vbNullString, REG_OPTION_NON_VOLATILE, _
KEY_ALL_ACCESS, _
0, hNewKey, lRetVal)
CreateNewKey = hNewKey
RegCloseKey(hNewKey)
End Function
...
i call for example:
CreateNewKey(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Today\Items\""Wireless""" )
Please help.
Thanks.
BongoUser said:
Hi, if i create a registry key i get an NonSupportet Exception.
Can someone Help?
Here the important part of my code:
Code:
Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const KEY_ALL_ACCESS = &H3F
Public Const REG_OPTION_NON_VOLATILE = 0
Private Declare Function RegCreateKeyEx Lib "coredll.dll" Alias "RegCreateKeyExW" ( _
ByVal hkey As Long, _
ByVal lpSubKey As String, _
ByVal Reserved As Long, _
ByVal lpClass As String, _
ByVal dwOptions As Long, _
ByVal samDesired As Long, _
ByVal lpSecurityAttributes As Long, _
ByRef phkResult As Long, _
ByRef lpdwDisposition As Long) As Long
Public Shared Function CreateNewKey(ByVal lSection As Long, _
ByVal sNewKeyName As String) As Long
Dim hNewKey As Long
Dim lRetVal As Long
RegCloseKey(lSection)
--HERE--> lRetVal = RegCreateKeyEx(lSection, sNewKeyName, 0, _
vbNullString, REG_OPTION_NON_VOLATILE, _
KEY_ALL_ACCESS, _
0, hNewKey, lRetVal)
CreateNewKey = hNewKey
RegCloseKey(hNewKey)
End Function
...
i call for example:
CreateNewKey(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Today\Items\""Wireless""" )
Please help.
Thanks.
Click to expand...
Click to collapse
Hi,
1) I wouldn't use lRetVal for the last parameter and the return function value. The last parameter returns the disposition value and the function return value returns 0 for success or an error that you can find in WINERROR.H and so in MSDN documentation.
If it is not the problem then:
2) In place of trying to create a key in HKLM, try first in HKCU, maybe the problem doesn't reside in the code but in the fact that you are trying to create a key in HKLM where you need "authorization" to do it. Your application needs to have privileges like being signed.
Hope it helps,
Cheers,
.Fred
ps.: use a real program language like C/C++. VB is crap!!!
dotfred said:
Hi,
1) I wouldn't use lRetVal for the last parameter and the return function value. The last parameter returns the disposition value and the function return value returns 0 for success or an error that you can find in WINERROR.H and so in MSDN documentation.
If it is not the problem then:
2) In place of trying to create a key in HKLM, try first in HKCU, maybe the problem doesn't reside in the code but in the fact that you are trying to create a key in HKLM where you need "authorization" to do it. Your application needs to have privileges like being signed.
Hope it helps,
Cheers,
.Fred
ps.: use a real program language like C/C++. VB is crap!!!
Click to expand...
Click to collapse
Hi,
it works nowm thanks.
I have found a working sample in www.

[REQ]Remapping Camera shot key to volume button?

Hi there,
First of all I tried searching on google and also in this forum itself but I cant find anything related and so i decided to create a new thread on this.
If there anyway via tweaking the registry that i can make use of the volume key on the blackstone to take pictures instead of using the touchscreen? I believe this is possible
I find taking picture using a touchscreen is really difficult.
I read from http://wiki.xda-developers.com/index.php?pagename=HTC_Blackstone_Overview that this is possible by remapping the volume rocker.
Does any know how?
Will anyone be able to help?
I'm requesting this also. HTC should have made an option for us to choose for this from the beginning.
Request also here!
Sorry, I added this "remap volume rocker Solution" because I thought it was possible, but I actually didn't try it. So let's keep this thread to find a way to do it.
Remapping keys is through AE Button Plus or MobileMagic.
Right now we only have the choice of "touch" or "touch and hold" the virtual on-screen button to "auto-focus + shot".
We need to find out if there is any keyboard shortcut associated to that function.
I tried to use the "enter key" fonction remaped to Volume Up with AE Button Plus, but it didn't work.
Does the HTC Touch Pro have HTC's Camera application? maybe they know a keyboard shortcut? Let's ask.
I guess it will be possible.... just that we need the experts here to show us how to...
[APP] CameraButton
To solve this problem. I thought of a very simple solution:
Instead of us clicking the on-screen camera button, we need an application "CameraButton", which will click on the screen for us, then we just need to map a hardware button to that application.
Simple isn't it?
So here is the C# code for the CameraButton application:
Code:
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
namespace CameraButton
{
class Program
{
[System.Runtime.InteropServices.DllImport("coredll.DLL", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
public static extern IntPtr FindWindow(string lpClassName,string lpWindowName);
[System.Runtime.InteropServices.DllImport("coredll.DLL", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
static extern bool SetForegroundWindow(IntPtr hWnd);
[System.Runtime.InteropServices.DllImport("coredll.dll")]
static extern bool SetCursorPos(int X, int Y);
[System.Runtime.InteropServices.DllImport("coredll.dll")]
static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint dwData, int dwExtraInfo);
[Flags]
public enum MouseEventFlags
{
LEFTDOWN = 0x00000002,
LEFTUP = 0x00000004,
MIDDLEDOWN = 0x00000020,
MIDDLEUP = 0x00000040,
MOVE = 0x00000001,
ABSOLUTE = 0x00008000,
RIGHTDOWN = 0x00000008,
RIGHTUP = 0x00000010
}
static void Main(string[] args)
{
IntPtr cameraHandle;
cameraHandle = FindWindow(null, "Camera");//search camera app
if (cameraHandle == IntPtr.Zero)// cannot find it then launch it
{
Process cam = Process.Start(new ProcessStartInfo("Camera.exe", ""));
//cameraHandle = cam.MainWindowHandle;
}
else // can find it then set position then click
{
//SetForegroundWindow(cameraHandle);// we assume we already have the focus on the camera app
SetCursorPos(240, 750 );//set position to the on-screen camera button
mouse_event((uint)MouseEventFlags.LEFTDOWN, 0, 0, 0, 0);
mouse_event((uint)MouseEventFlags.LEFTUP, 0, 0, 0, 0);
}
}
}
}
Why do I give the code rather than the binary?
Because unfortunately this code doesn't work (yet).
Let me explain a bit more:
This application doesn't need to keep running in the background, it just can do 2 things. Start the camera app if it's not already started, or just click at a specifically chosen position.
If I set the position to (0,0), my program will click at the upper-left corner of the screen, and hit the start button, therefore the start menu appears.
However if I try to click on the camera application, it doesn't have any effect!
Actually if I click somewhere else than the on-screen camera button, it should still react to the click: the little cross should move to the clicked place as part of the Touch Focus feature of HTC's camera app.
But here again, nothing happen.
Since it's my first app on WiMo, I might have done a mistake somewhere, but I can't see where.
Any XDA-developer can spot what's wrong with my code?
please see http://forum.xda-developers.com/showthread.php?t=471321
The Problem is the HTC Application, it blocks any keydown event
I did it Application released soon!
http://www.scilor.com/leocameraanykey.html

Hiding/showing a form (vb.net)

I am trying to replace my contacts program with one I wrote myself but I'm having a little problem getting the form to hide and then show again?
I would like to start my app from a button, easy enough but I'm a little confused with hiding it again. I can hide the form but if I press the button again nothing happens but I'd like my app to show itself again?
Could someone please help the village idiot and point me in the right direction please?
Ok solved my problem. I used another exe to boot the program and if it was already booted then show the program via the API.
Imports System.Runtime.InteropServices
Imports System.Diagnostics
Module ModMain
<DllImport("coredll")> _
Public Function FindWindow(ByVal lpClass As String, ByVal lpTitle As String) As IntPtr
End Function
<DllImport("CoreDll")> _
Public Function ShowWindow(ByVal hwnd As IntPtr, ByVal nCmdShow As Integer) As Boolean
End Function
<DllImport("CoreDll")> _
Public Function SetForegroundWindow(ByVal hWnd As IntPtr) As Boolean
End Function
Const SW_HIDE As Integer = 0
Const SW_SHOW As Integer = 5
Public Sub Main()
Dim hWnd As Long = FindWindow("#NETCF_AGL_BASE_", "Contacts")
If hWnd = IntPtr.Zero Then
Dim AP As New Process
AP.StartInfo.FileName = "Program Files\ContactsList2\ContactsList2.exe"
AP.Start()
Else
ShowWindow(hWnd, SW_SHOW)
SetForegroundWindow(hWnd)
End If
End Sub
End Module

Categories

Resources