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?
i have this code:
<DllImport("coredll")> _
Private Shared Function SetDevicePower(ByVal pvDevice As String, ByVal dwDeviceFlags As Integer, ByVal DeviceState As devicepowerstate) As Integer
End Function
Public Enum devicepowerstate : int
Unspecified = -1
D0 = 0
D1 = 1
D2 = 2
D3 = 3
D4 = 4
End Enum
Const POWER_NAME As Integer = &H1
SetDevicePower("BKL1:", POWER_NAME, devicepowerstate.D3)
when i use D3, my backlight goes DIM (which is what i am aiming for) but when my LCD goes off (idle mode) and then i click on any key to reactivate my DIMMED backlight, the LCD does TURN ON but my backlight stays OFF.
im using it on my T-Mobile SDA WM5.
I am trying to create a simple stopwatch like app and am having a hard time figuring it out.
in vb.net i can simply use Timer.Start() or Timer.Stop()
This will not work in the .net cf though. I googled the topic for over an hour and did a quick search on the forum and found no result.
Can anyone help me with a way around this, there has to be something simple I am missing or another way to do it. I just need a timer i can start, stop, pause and resume.
Thanks in advance.
Set the timer's Enabled property to true/false.
that works to start and stop it but if i want to pause and then resume it starts from the very begging instead of where it was paused.
ex: pause after 10sec. wait 10sec and hit resume....the timer jumps to 20sec instead of going to 11sec
Why not increment a variable when the timer ticks? Post some sample code here and we could help you debug it....
Do the calculations by using DateTime and TimeSpan.
Code:
Public Class Form1
Dim startTime As DateTime
Private Sub Timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer.Tick
Dim span As TimeSpan = DateTime.Now.Subtract(startTime)
lblTimer.Text = span.Hours.ToString & ":" & span.Minutes.ToString & ":" & span.Seconds.ToString
btnStop.Enabled = True
btnPause.Enabled = True
End Sub
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
startTime = DateTime.Now()
Timer.Start()
If (Timer.Enabled = True) Then
btnStart.Text = "Restart"
End If
End Sub
Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
If (Timer.Enabled) Then
Timer.Stop()
End If
End Sub
Private Sub btnPause_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPause.Click
If (Timer.Enabled) Then
Timer.Stop()
btnPause.Text = ("Resume")
Else : Timer.Start()
btnPause.Text = ("Pause")
End If
End Sub
End Class
now the problem is timer.start and timer.stop do not work as they are not included in the cf
I code in C#, but don't you need to declare a variable of type Timer to use it? I don't think there are any static methods for the Timer class.
the above code works fine in the standard .net framework but the start and stop methods are not in the compact framework so i need to find a way around that
Sorry, I got confused with the naming conventions - I thought Timer was a class reference.
Start and Stop works in the full framework, but the logic of your code is wrong - you are always subtracting the _start_ time from the current time when the timer ticks. This is why when you resume, it's still counting how many seconds has passed since you pressed Start.
This should work:
Code:
Public Class Form1
Dim startTime As DateTime
Dim span As TimeSpan
Dim hours, minutes, seconds As Integer
Private Sub Timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer.Tick
span = DateTime.Now.Subtract(startTime)
lblTimer.Text = span.Hours.ToString & ":" & span.Minutes.ToString & ":" & span.Seconds.ToString
End Sub
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
startTime = DateTime.Now()
Timer.Enabled = True
If (Timer.Enabled = True) Then
btnStart.Text = "Restart"
End If
End Sub
Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
Timer.Enabled = False
End Sub
Private Sub btnPause_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPause.Click
If (Timer.Enabled) Then
Timer.Enabled = False
btnPause.Text = ("Resume")
hours = span.Hours
minutes = span.Minutes
seconds = span.Seconds
Else
startTime = DateTime.Now.Subtract(New TimeSpan(hours, minutes, seconds))
Timer.Enabled = True
btnPause.Text = ("Pause")
End If
End Sub
End Class
Man, coding in VB brings back memories...
...i see your point thanks a lot...as soon as i am done backing the hard drive up in my msi wind i will give this a shot...thanks again
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
I am currently working on my "SciLor's WiMoBlue". The new protocol is ready. Everything works fine, until I send much data at the same time.
For example if I try to send an image in that way:
Code:
Public Sub SendImage(ByVal Image As Bitmap, ByVal Position As Point, ByVal Format As ImageFormat)
Dim PosX, PosY, Width, Height As Byte()
Dim ImageStream As New IO.MemoryStream
Dim ImageLength As Integer
Dim ImageLengthBytes As Byte()
Dim ImageBuffer(MaxChunkSize - HeaderSize - 1) As Byte
PosX = BitConverter.GetBytes(Position.X)
PosY = BitConverter.GetBytes(Position.Y)
Width = BitConverter.GetBytes(Image.Width)
Height = BitConverter.GetBytes(Image.Height)
Image.Save(ImageStream, ImageFormat2ImagingFormat(Format))
ImageStream.Seek(0, SeekOrigin.Begin)
ImageLength = ImageStream.Length
ImageLengthBytes = BitConverter.GetBytes(ImageLength)
SendData(BuildCommand(BaseProtocol.Image, ImageProtocol.Initiate, CombineBytes(PosX, PosY, Width, Height, ImageLengthBytes)))
Thread.Sleep(2000)
Dim DataPos As Integer
For DataPos = 0 To ImageStream.Length - MaxChunkSize - HeaderSize - 1 Step MaxChunkSize - HeaderSize
ImageStream.Read(ImageBuffer, 0, MaxChunkSize - HeaderSize)
SendData(BuildCommand(BaseProtocol.Image, ImageProtocol.Data, ImageBuffer))
'WaitForNextChunk = True
'Do While WaitForNextChunk = True
'Loop
'Thread.Sleep(2000)
Next
ImageBuffer = New Byte(ImageLength - DataPos - 1) {}
ImageStream.Read(ImageBuffer, 0, ImageBuffer.Length)
SendData(BuildCommand(BaseProtocol.Image, ImageProtocol.End, ImageBuffer))
End Sub
SendData:
Code:
If Data.Length > MaxChunkSize Then
MsgBox("Data to long... " & vbNewLine & "SendSize:" & Data.Length & vbNewLine & "MaxSize:" & MaxChunkSize)
Else
If btClient.Connected = True And isRecieving = True Then
btStream.Write(Data, 0, Data.Length)
btStream.Flush()
End If
End If
Recieving Part:
Code:
While isRecieving = True
If btStream IsNot Nothing And btStream.DataAvailable = True Then
Try
Recieved = btStream.Read(myHeader, 0, myHeader.Length)
If myHeader(0) = HeaderIdentifier And myHeader(1) = OtherModeHeader Then
btStream.Read(myDataSize, 0, 2)
DataLength = BitConverter.ToInt16(myDataSize, 0)
myBuffer = New Byte(DataLength - 1) {}
Recieved = 0
Do Until Recieved = DataLength
If btStream.DataAvailable = True Then
Recieved += btStream.Read(myBuffer, Recieved, DataLength - Recieved)
End If
Loop
ExecuteCommand(myHeader(2), myHeader(3), myBuffer)
Else
Debug.WriteLine("WrongData")
Exit While
End If
Catch ex As Exception
Debug.WriteLine(ex.Message)
If Recieved = 0 Then
Exit While
End If
End Try
End If
End While
If I send the image, without Thread.Sleeps (huighe ones). The recieving stream gets weird. The gets btStream.DataAvailable = False forever. If I remove that ckeck, it hangs at the btStream.Read.
I also tried to fix that with waiting for the answer of the server, but the problem doesn't get solved.
Do you have any idea how to fix that problem?. In that speed the image sending is worthless
SciLor