Thanks for the replay, you GetAsyncKeyState() suggestion works great. sofar I have:
'#################################
'# #
'# Keyboard Encoder #
'# v0.0.1 #
'# Dec 22, 2009 #
'# #
'#################################
'---------- Includes ------------
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
'---------- Variables -----------
Const HaltKey = &H1B 'Esc
Const Enc_A = &H5A 'Z
Const Enc_B = &H58 'X
'---------- Main Function ------------
Sub Main()
Message("") 'Clear The Message Space
Do
If HaltKeyPressed() = true Then
Message "Macro Aborted!"
Exit Do
End If
If A_Result() = true Then
Message "A!"
End If
If B_Result() = true Then
Message "B!"
End If
If A_Result() And B_Result() = true Then
Message "A+B!"
End If
Sleep(100)
Loop
End Sub
'--------------------------------------
'------------ Escape Routine ----------
Sub HaltKeyPressed()
Dim Result As Boolean
If GetAsyncKeyState(HaltKey) < 0 Then
Result = true
Else
Result = false
End If
HaltKeyPressed = Result
End Sub
'--------------------------------------
'------------ Encoder Capture ---------
Sub A_Result()
Dim Result As Boolean
If GetAsyncKeyState(Enc_A) < 0 Then
Result = true
Else
Result = false
End If
A_Result = Result
End Sub
Sub B_Result()
Dim Result As Boolean
If GetAsyncKeyState(Enc_B) < 0 Then
Result = true
Else
Result = false
End If
B_Result = Result
End Sub
'-----------------------------------------
Just as a basic setup to make sure my encoder is outputting properly.
I have a modified keyboard map that shifts the encoder keys (not actually z or x) into unused virtual keys so not to interfere with normal keyboard operations.
Now I only need to figure out how to turn it all into a ++ or -- rotation so I can push some buttons.
------------- EDIT ---------------
I see GetKeyState() will give a 1 or 0 depending on key state and will not be cleared by another app polling the GetAsyncKeyState() function but for some reason the a-z/A-Z/0-9's all give a 1 no matter whats going on. I suck at VB and theirs no variable monitor in Mach so I have no idea what the returns are really doing. The MSDN database shows WM_KEYUP / WM_KEYDOWN Notification's but I have no idea how to use these either...
Once I figure out the key polling this is the general idea:
Dim Pos_Old As Integer
Dim Pos_New As Integer
Pos_New = GetKeyState(Enc_A)
Pos_New = (GetKeyState(Enc_B) << 1)
This will create a 2bit variable that I can do the following checks on:
if Pos_New = Pos_Old Then Exit
if Pos_New is one of these in a case statement:
0:1 ++
0:2 --
1:3 ++
1:0 --
3:2 ++
3:1 --
2:0 ++
2:3 --
Then simulate a button push in the right direction on whichever axis is selected.