keys are set as constants , is there anyway I can change them. or at least substitute them for the duration of my program
: keys are set as constants , is there anyway I can change them. or at least substitute them for the duration of my program
If keys are set as constants, you will not be able to change them during program execution. Your best bet is to convert them to variables.
If you want to protect the integrity of the data but be able to change, you can encapsulate the keys in a class or module and write property procedures that control access to the key value. Make the properties shared so that you dont have to instantiate the class.
Public Class Keys
Private Shared mKeyA As String
Private Shared mKeyB As String
Public Shared Property KeyA As String
Set(ByVal value As String)
mKeyA = value
Public Shared Property KeyB As String
Set(ByVal value As String)
KeyB = value
Then you can access the keys like so ...
Dim key As String = Keys.KeyA
keys.KeyB = "123456"
The advantages of using property procedures lies in the fact thatyou can arbitrate extra conversions on the key before it gets stored. Inside the class u can write private (must be shared if manipulating shared data) functions that swap keys and whatever you need.
If you are storing a ton of keys, consider using a hash table object.
Dim ht As New hashTable
ht.Add("Key A", "123456")
ht.Add("Key B", "2345")
ht.Add("Key C", "345455")
Dim keyA As String = ht("Key A").ToString
I dunno if any of this helps. But from what minor info you gave I assume some of thgis will give some ideas.
I did find your bit greatly informative and will keep it handy for further use. But, correct me if I am wrong?. This is all obsolete as far as other applications are concerned. I really want to use the keys "Globally" so I can activate them from any application. I think I have to set a hook. Really, I want to know if I am on the right ack?
I am delving a little deep for my level of programming. The api is not strait forward for a new programmer. I think I am close to getting it. I read a couple of articles. I will also get you back if I come across the solution so that you can better understand my problem. It also might be useful if someone else has the same trouble as I did.
Thanks for your time always appreciated ...by tsikman
Ok I have figured out how to change my keys after months of headache.
one thing I need to know now to complete my task. I am sending keys.
I think I am sending them as text.
for example sendkeys.send(" ") sends a space
sendkeys.send(space) sends a 32
I need the to get it to interact with the program
since there is no text input field,
Is there such thing as a space bar command in contrast to a space as a text input?
: Ok I have figured out how to change my keys after months of headache.
: one thing I need to know now to complete my task. I am sending keys.
: I think I am sending them as text.
: for example sendkeys.send(" ") sends a space
: sendkeys.send(space) sends a 32
: I need the to get it to interact with the program
: since there is no text input field,
: Is there such thing as a space bar command in contrast to a space as a text input?
I was actually gonna mention about the SendKeys class, but wasn't sure what you were exactly doing. But try this:
Documentation suggest using these win32 api functions to set the focus on the application you want to send keys to:
[b][red]This message was edited by Tsikman at 2003-9-22 7:50:5[/red][/b][hr]
you don't have to read this if you haven't time, but if it helps you to help me. I am all for it.(sorry I don't know how to grey out areas to make it easier to read).
Public Declare Function UnhookWindowsHookEx Lib "user32" _
(ByVal hHook As Integer) As Integer
Declare Sub keybd_event Lib "user32.dll" _
(ByVal bVk As Byte, ByVal bScan As Byte, _
ByVal KEYEVENTF_KEYUP As Long, ByVal dwExtraInfo As Long)
Public Declare Function SetWindowsHookEx Lib "user32" _
Alias "SetWindowsHookExA" (ByVal idHook As Integer, _
ByVal lpfn As KeyboardHookDelegate, ByVal hmod As Integer, _
ByVal dwThreadId As Integer) As Integer
Private Declare Function GetAsyncKeyState Lib "user32" _
(ByVal vKey As Integer) As Integer
Private Declare Function CallNextHookEx Lib "user32" _
(ByVal hHook As Integer, _
ByVal nCode As Integer, _
ByVal wParam As Integer, _
ByVal lParam As KBDLLHOOKSTRUCT) As Integer
Public Structure KBDLLHOOKSTRUCT
Public vkCode As Integer
Public scanCode As Integer
Public flags As Integer
Public time As Integer
Public dwExtraInfo As Integer
' Low-Level Keyboard Constants
Private Const HC_ACTION As Integer = 0
Private Const LLKHF_EXTENDED As Integer = &H1
Private Const LLKHF_INJECTED As Integer = &H10
Private Const LLKHF_ALTDOWN As Integer = &H20
Private Const LLKHF_UP As Integer = &H80
' Virtual Keys
Public Const VK_TAB = &H9
Public Const VK_CONTROL = &H11
Public Const VK_ESCAPE = &H1B
Public Const VK_X = &H58
Public Const VK_SPACE = &H39
Private Const WH_KEYBOARD_LL As Integer = 13&
Public KeyboardHandle As Integer
Const KEYEVENTF_KEYUP = &H2
Const KEYEVENTF_EXTENDEDKEY = &H1
' Implement this function to block as many
' key combinations as you'd like
Public Function IsHooked( _
ByRef Hookstruct As KBDLLHOOKSTRUCT) As Boolean
Debug.WriteLine("Hookstruct.vkCode: " & Hookstruct.vkCode)
Debug.WriteLine(Hookstruct.vkCode = VK_ESCAPE)
Debug.WriteLine(Hookstruct.vkCode = VK_TAB)
If (Hookstruct.vkCode = VK_X) Then
keybd_event(&H20, 0, KEYEVENTF_EXTENDEDKEY, 0)
keybd_event(&H20, 0, KEYEVENTF_KEYUP, 0)
Call HookedState("key was pressed")
Private Sub HookedState(ByVal Text As String)
Public Function KeyboardCallback(ByVal Code As Integer, _
ByVal wParam As Integer, _
ByRef lParam As KBDLLHOOKSTRUCT) As Integer
If (Code = HC_ACTION) Then
If (IsHooked(lParam)) Then
Return CallNextHookEx(KeyboardHandle, _
Code, wParam, lParam)
Public Delegate Function KeyboardHookDelegate( _
ByVal Code As Integer, _
ByVal wParam As Integer, ByRef lParam As KBDLLHOOKSTRUCT) _
Private callback As KeyboardHookDelegate
Public Sub HookKeyboard()
callback = New KeyboardHookDelegate(AddressOf KeyboardCallback)
KeyboardHandle = SetWindowsHookEx( _
WH_KEYBOARD_LL, callback, _
Public Sub CheckHooked()
If (Hooked()) Then
Debug.WriteLine("Keyboard hook failed: " & Err.LastDllError)
Private Function Hooked()
Hooked = KeyboardHandle <> 0
Public Sub UnhookKeyboard()
If (Hooked()) Then
When you respond to a posting and want to to display the nifty grey code blocks just use ...
[ code ]
code goes here
[ /code ]
Accept there are no spaces inside the brackets.
I will have to carefully scrutinize this code when I get a chance today. L8r.
It looks like you're new here. If you want to get involved, click one of these buttons!
Assembly Code Share
Getting started in assembly
C and C++
C/C++ on Linux/Unix
C/C++ Windows API
C++ Game Development
Delphi and Kylix
Java Server Pages
Access databases and VB
Advance Visual Basic
DirectX Game dev
Newbie Game Programmers
Cooling & Overclocking
Database & SQL
Sound & Music
FreeLance Software City
C# & VB.NET School Support
Join the Team
Comments on this site
New programming languages
Off topic board
Mobile & Wireless
Operating Systems & Platforms
Witsbits Go Cloud
Embedded / RTOS
Windows CE & Pocket PC
Networking And Security
Windows 2003 Server
RUP & UML
Quality & Testing
Active Server Pages
HTML & WEB-Design
Mobile Internet & Messaging
WEB-Services / SOAP
In this Discussion