Hi!
This is abit cheezy, because I understand what's wrong, but not how to fix it.
Overview of the problem:
I'm making a small program that registers a hotkey to the system (Ctrl + F)
When the hotkey is pressed, a program is being started using the ShellExecute function.
This workes 100% fine, no problem with that.
Problem situation:
I figured that Ctrl+F wasn't ideal for all users. Thus, I wanted to let them choose wich
key to use instead of having just one pre-determined key. So I added a text-box where
the user can press the key he/she wants. When the user clicks "Save Config", I have a
simple WriteINI module wich then write the information in an INI-file. When the form loads, it
gets the key back in from ReadINI module. Just a simple save/load function. It works 100%
and there is actually no need for anything more advanced.. :b
The code:
The code to register the hotkey:
Now... RegisterHotKey is using Long wich can only contain variables/syntaxes. I do understand that.
RegisterHotKey(Me.hwnd, &HBFFF&, MOD_CONTROL, vbKeyF)
vbKeyF is the code it uses to know that F is the key. When I save the key the user has selected from the text-box,
I have a Label wich gets the caption:
This is how the key is saved. Simple as that. As a string in a text/INI file.
ret = RegisterHotKey(Me.hwnd, &HBFFF&, MOD_CONTROL, lblHotKey.Caption)
That code gives me Runtime Error 13: Type mismatch
Now.. I do understand that the function to register the hotkey doesn't
accept a string as a value, as it's expecting a pure VB syntax/statement and not
from a string.
So the question y'all have been waiting for:
Help?!
How can I store the key and then load it back in the code?
Do I have to convert the string in a "KeyPress" event of the TextBox?
If so, could someone help me with that? :b
Kind regards! (:
//Chris-Mario
This is abit cheezy, because I understand what's wrong, but not how to fix it.
Overview of the problem:
I'm making a small program that registers a hotkey to the system (Ctrl + F)
When the hotkey is pressed, a program is being started using the ShellExecute function.
This workes 100% fine, no problem with that.
Problem situation:
I figured that Ctrl+F wasn't ideal for all users. Thus, I wanted to let them choose wich
key to use instead of having just one pre-determined key. So I added a text-box where
the user can press the key he/she wants. When the user clicks "Save Config", I have a
simple WriteINI module wich then write the information in an INI-file. When the form loads, it
gets the key back in from ReadINI module. Just a simple save/load function. It works 100%
and there is actually no need for anything more advanced.. :b
The code:
Code:
Private Declare Function RegisterHotKey Lib "user32" (ByVal hwnd As Long, ByVal id As Long, ByVal fsModifiers As Long, ByVal vk As Long) As Long
Private Declare Function UnregisterHotKey Lib "user32" (ByVal hwnd As Long, ByVal id As Long) As Long
Private Declare Function PeekMessage Lib "user32" Alias "PeekMessageA" (lpMsg As msg, ByVal hwnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long, ByVal wRemoveMsg As Long) As Long
Private Declare Function WaitMessage Lib "user32" () As Long
Private bCancel As Boolean
The code to register the hotkey:
Code:
Dim ret As Long
bCancel = False
ret = RegisterHotKey(Me.hwnd, &HBFFF&, MOD_CONTROL, vbKeyF)
RegisterHotKey(Me.hwnd, &HBFFF&, MOD_CONTROL, vbKeyF)
vbKeyF is the code it uses to know that F is the key. When I save the key the user has selected from the text-box,
I have a Label wich gets the caption:
Code:
Private Sub txtHotKey_Change()
txtHotKey.Text = UCase(txtHotKey.Text)
lblHot.Caption = "vbKey" & txtHotKey.Text
End Sub
ret = RegisterHotKey(Me.hwnd, &HBFFF&, MOD_CONTROL, lblHotKey.Caption)
That code gives me Runtime Error 13: Type mismatch
Now.. I do understand that the function to register the hotkey doesn't
accept a string as a value, as it's expecting a pure VB syntax/statement and not
from a string.
So the question y'all have been waiting for:
Help?!
How can I store the key and then load it back in the code?
Do I have to convert the string in a "KeyPress" event of the TextBox?
If so, could someone help me with that? :b
Kind regards! (:
//Chris-Mario