Solved

I need help with this VB program

Posted on 2011-03-10
8
528 Views
Last Modified: 2013-11-26
I have a keypad that i use on my keyboard for music I need help with the vb script to make it work right I would like to instead of just tapping each button once on the xkeys keypad, can the programming be altered to take in 'double button' inputs.  I would like to alter some of the buttons to accept double digit inputs.  To try to describe it, you would tap '00' , '01' , '02' , .. and so on all the way to '99'.
What this would allow me to do, would be to have 100 commands contained within those 10 buttons.  That's the way I have a keypad set up now that I'm using..but that keypad is so old already and the software has stability issues as os's keep evolving.  It's called 'AutoKEY' and it dates back to the win95 days (see attached image).
. if any one can help with this i would be so much greatful. the code is here
'=?=?=?= MW3 Header Start =?=?=?=?=?=?=?=?=?=?=?=?=[MWTAG1]
' Script Type: MacroWorks 3 Device Script
' Device Name: X-keys Desktop
' Device Description: 20 Button HID Controller
' Script Name:
' Script Description: Macros for X-keys Desktop
' PID: 641
' Firmware: SE
' MW3 Version: 15
' Script Language: Visual Basic
' Script Template: Beta 1.0 
' Format: Unicode 8
' P.I. Engineering, Inc. 
' "The No Slogan Company"
' Williamston, Michigan, USA
' www.xkeys.com
' Start Date:  12-15-09, 6:43: 34 AM
' Last Update: 12-15-09, 6:43: 34 AM
'=?=?=?= MW3 Header End    =?=?=?=?=?=?=?=?=?=?=?=?=[/MWTAG1]

'=?=?=?= Notes Start =?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=[MWTAG2]
'  User comment notes can go here. 
'=?=?=?= Notes End   =?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=[MWTAG2]

Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic

Public Class Script 
Implements Interfaces.IScript '[MWTAG12]
	
'=?=?=?= Initialize Variables Start =?=?=?=?=?=?=?=?=[MWTAG3]
	Dim MW3 As Interfaces.MW3
	Dim MyDevice As Integer() = {641, -1, 1} 'Device Descriptor [MWTAG8]
	Dim AppName As String = "" 'Active application name
	Dim AppTitle As String = "" 'Active application title
	Dim Layer_Red As Integer = 0 'Red,3
'=?=?=?= Initialize Varibles End  =?=?=?=?=?=?=?=?=?=[/MWTAG3]

	Public Sub Initialize(MW3 As Interfaces.MW3) Implements Interfaces.IScript.Initialize
		Me.MW3 = MW3
	End Sub
	
	Public Sub ScriptLoad() Implements Interfaces.IScript.ScriptLoad
		LEDset()	
	End Sub
	
	Public Function ScriptUnload() As Boolean Implements Interfaces.IScript.ScriptUnload
	End Function
	
	Public Sub SysPowerChange(PowerState As Byte) Implements Interfaces.IScript.SysPowerChange
	End Sub

	Public Sub ActiveAppChange(ActiveAppTitle As String, ActiveAppName As String) Implements Interfaces.IScript.ActiveAppChange
		AppName= ActiveAppName
		AppTitle= ActiveAppTitle
	End Sub
	
	Public Sub DeviceChange(DevInfo As Integer(), plugged As Boolean) Implements Interfaces.IScript.DeviceChange
		
	End Sub

'=?=?=?= Digital State Change Event Start =?=?=?=?=?=?=?=[MWTAG4]
	Public Sub XKEvent(CID As Integer, State As Boolean, Repeat As Integer, TimeStamp as Long, MessageData As Integer) Implements Interfaces.IScript.XKEvent
		Select Case CID 'Button Check Start [MWTAG9]
		Case 1001 'Button 001
			If State 'Pressed [MWTAG10]
			Else 'Released [MWTAG11]
			End If 'Press-Release [/MWTAG10/MWTAG11]
		Case 1002 'Button 002
			If State 'Pressed [MWTAG10]
			Else 'Released [MWTAG11]
			End If 'Press-Release [/MWTAG10/MWTAG11]
		Case 1003 'Button 003
			If State 'Pressed          [MWTAG10]
			Else 'Released             [MWTAG11]
			End If 'Press-Release      [/MWTAG10/MWTAG11]
		Case 1004 'Button 004
			If State 'Pressed [MWTAG10]
			Else 'Released [MWTAG11]
			End If 'Press-Release [/MWTAG10/MWTAG11]
		Case 1005 'Button 005
			If State 'Pressed [MWTAG10]
			Else 'Released [MWTAG11]
			End If 'Press-Release [/MWTAG10/MWTAG11]
		Case 1006 'Button 006
			If State 'Pressed [MWTAG10]
			Else 'Released [MWTAG11]
			End If 'Press-Release [/MWTAG10/MWTAG11]
		Case 1007 'Button 007
			If State 'Pressed [MWTAG10]
			Else 'Released [MWTAG11]
			End If 'Press-Release [/MWTAG10/MWTAG11]
		Case 1008 'Button 008
			If State 'Pressed          [MWTAG10]
			Else 'Released             [MWTAG11]
			End If 'Press-Release      [/MWTAG10/MWTAG11]
		Case 1009 'Button 009
			If State 'Pressed          [MWTAG10]
			Else 'Released             [MWTAG11]
			End If 'Press-Release      [/MWTAG10/MWTAG11]
		Case 1010 'Button 010
			If State 'Pressed [MWTAG10]
			Else 'Released [MWTAG11]
			End If 'Press-Release [/MWTAG10/MWTAG11]
		Case 1011 'Button 011
			If State 'Pressed          [MWTAG10]
			Else 'Released             [MWTAG11]
			End If 'Press-Release      [/MWTAG10/MWTAG11]
		Case 1012 'Button 012
			If State 'Pressed          [MWTAG10]
			Else 'Released             [MWTAG11]
			End If 'Press-Release      [/MWTAG10/MWTAG11]
		Case 1013 'Button 013
			If State 'Pressed          [MWTAG10]
			Else 'Released             [MWTAG11]
			End If 'Press-Release      [/MWTAG10/MWTAG11]
		Case 1014 'Button 014
			If State 'Pressed [MWTAG10]
			Else 'Released [MWTAG11]
			End If 'Press-Release [/MWTAG10/MWTAG11]
		Case 1015 'Button 015
			If State 'Pressed [MWTAG10]
			Else 'Released [MWTAG11]
			End If 'Press-Release [/MWTAG10/MWTAG11]
		Case 1016 'Button 016
			If State 'Pressed          [MWTAG10]
			Else 'Released             [MWTAG11]
			End If 'Press-Release      [/MWTAG10/MWTAG11]
		Case 1017 'Button 017
			If State 'Pressed [MWTAG10]
			Else 'Released [MWTAG11]
			End If 'Press-Release [/MWTAG10/MWTAG11]
		Case 1018 'Button 018
			If State 'Pressed [MWTAG10]
			Else 'Released [MWTAG11]
			End If 'Press-Release [/MWTAG10/MWTAG11]
		Case 1019 'Button 019
			If State 'Pressed [MWTAG10]
			Else 'Released [MWTAG11]
			End If 'Press-Release [/MWTAG10/MWTAG11]
		Case 1020 'Button 020
			If State 'Pressed [MWTAG10]
			Else 'Released [MWTAG11]
			End If 'Press-Release [/MWTAG10/MWTAG11]
		Case 1021 'ProgSwitch  -restricted-
			If State 'Pressed [MWTAG10]
				'<Open GUI>
				MW3.SetGUI(MyDevice,0,true)
				'</Open GUI>
			Else 'Released [MWTAG11]
				'<Close GUI>
				MW3.SetGUI(MyDevice,0,false)
				'</Close GUI>
			End If 'Press-Release [/MWTAG10/MWTAG11]
		End Select 'Button Check End [/MWTAG9]

		If Repeat = 0 
			LEDset() ' Set the Indicator LEDs
		End If
	End Sub	
'=?=?=?= Digital State Change Event End ?=?=?=?=?=?=?=?=?=[/MWTAG4]

'=?=?=?=Indicator LEDs Start =?=?=?=?=?=?=?=?=?=?=?=?=?=?=[MWTAG5]
	Public Sub LEDset() 
		If Layer_Red = 1
			MW3.SetLED(MyDevice,3001,0)
			MW3.SetLED(MyDevice,3002,1) 'Turn on the Red Indicator LED
		Else
			MW3.SetLED(MyDevice,3002,0)'Turn off the Red Indicator LED
			MW3.SetLED(MyDevice,3001,1)
		End if
	End Sub 
'=?=?=?= Indicator LEDs End ?=?=?=?=?=?=?=?=?=?=?=?=?=?=?=[/MWTAG5]
	
'=?=?=?=String Data Received Event Start =?=?=?=?=?=?=?=?=[MWTAG6]
	Public Sub XKStringEvent(CID As Integer, StringData As String, Repeat As Integer, TimeStamp as Long, MessageData As Integer) Implements Interfaces.IScript.XKStringEvent
		'String data is sent to this routine, XK-24 does not send string data but this is required for MW3 compatibility. 
	End Sub
'=?=?=?= String Data Received Event End ?=?=?=?=?=?=?=?=?=[/MWTAG6]

'=?=?=?= Analog Data Received Event Start =?=?=?=?=?=?=?=?[MWTAG7]
	Public Sub XKAnalogEvent(CID As Integer, AnalogValue As Integer(), Repeat As Integer, TimeStamp as Long, MessageData As Integer) Implements Interfaces.IScript.XKAnalogEvent
		'Analog data is sent to this routine, XK-24 does not send analog data but this is required for MW3 compatibility. 
	End Sub
'=?=?=?= Analog Data Received Event End ?=?=?=?=?=?=?=?=?=[/MWTAG7]

End Class '[/MWTAG12]

Open in new window

x-keys.jpg
0
Comment
Question by:hank2011
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 45

Expert Comment

by:aikimark
ID: 35109887
@Hank

This keyboard interface seems to respond to keydown/keyup events.  The way I would approach your stated result is that I would add two variables at the module level to track the last key up number and the time of that last key up.  Add code that will compare the prior key up number to the current key up number, if it is the same number, then subtract the prior timestamp value from the current timestamp.  You will need to set a time threshhold,  below which a double-tap of a key will result in some different action, rather than two of those digits.

In the special case (double-click), you will need to cancel the second character from getting to the program.  When I've done something like this for VB textbox controls, I set the Keycode=0.
0
 
LVL 1

Author Comment

by:hank2011
ID: 35110024
Aikimark,

can you show me example of this.
0
 
LVL 45

Expert Comment

by:aikimark
ID: 35110243
>>can you show me example of this

Not with your special keyboard interface code.

What experience do you have with VB programming?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:hank2011
ID: 35110648
I know a little in vb like how to do calulations event handles stuff like that. I program more in c#.
0
 
LVL 45

Expert Comment

by:aikimark
ID: 35112515
do you understand how to define variables?
do you know where general declarations is located?
do you know how to assign values to variables?
do you know how to compare variable values?
0
 
LVL 1

Author Comment

by:hank2011
ID: 35113432
yes i do understand all you wrote i just was needed sometype of example on the code to change so i can get this to work right thats all
0
 
LVL 45

Accepted Solution

by:
aikimark earned 500 total points
ID: 35113600
It might look something like this

option explicit
dim lngPriorKey As Long
dim dtPriorKeyTime As Long

'place the following code in the place you detect key up events
If currentkey = lngpriorkey then
  if cdbl(now-dtPriorKeyTime) < 0.0000029 Then  '< 1/4 sec
    'place code here to process double-click
  End If
  'cancel the currentkey somehow

  'save the current time
  dtPriorKeyTime  = now
else
  lngPriorKey = currentkey
  dtPriorKeyTime = now
end if

Open in new window

0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question