|
-
Feb 21st, 2004, 06:39 PM
#1
-
Feb 22nd, 2004, 01:47 AM
#2
Sleep mode
In the KeyDown Event do this :
VB Code:
If e.Control Then
'DO whatever
End If
And for the other question , check the static class . It have 70 different methods about all sys info .
-
Feb 22nd, 2004, 04:04 PM
#3
Originally posted by Pirate
In the KeyDown Event do this :
VB Code:
If e.Control Then
'DO whatever
End If
And for the other question , check the static class . It have 70 different methods about all sys info .
hmm thanks for the SystemInformation thingie
umm but is there a way to figure that out any time, without being in the keydown event?
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Feb 22nd, 2004, 09:57 PM
#4
Sleep mode
Originally posted by MrPolite
umm but is there a way to figure that out any time, without being in the keydown event?
The only way I can think of is : hotkey ! ! How ? can't think now , I need to sleep !
-
Feb 22nd, 2004, 11:55 PM
#5
umm no screw the hot keys. there is the GetKeyboardState API, but I just dont know how to use it exactly
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Feb 23rd, 2004, 02:23 AM
#6
Sleep mode
Example for GetKeyboardState API :
VB Code:
Const VK_CAPITAL = &H14
Const VK_NUMLOCK = &H90
Const VK_SCROLL = &H91
Const VK_USED = VK_SCROLL
Private Type KeyboardBytes
kbByte(0 To 255) As Byte
End Type
Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Long
Private Declare Function GetKeyboardState Lib "user32" (kbArray As KeyboardBytes) As Long
Private Declare Function SetKeyboardState Lib "user32" (kbArray As KeyboardBytes) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Dim kbArray As KeyboardBytes, CapsLock As Boolean, kbOld As KeyboardBytes
Private Sub Form_Load()
'KPD-Team 1999
'URL: [url]http://www.allapi.net/[/url]
'Get the current keyboardstate
GetKeyboardState kbOld
'Hide the form
Me.Hide
MsgBox "Keep your eyes on the little num-, shift- and scrolllock lights on the keyboard."
TurnOff VK_CAPITAL
TurnOff VK_NUMLOCK
TurnOff VK_SCROLL
Sleep 1000
TurnOn VK_NUMLOCK
Sleep 100
TurnOn VK_CAPITAL
Sleep 100
TurnOn VK_SCROLL
Sleep 300
TurnOff VK_NUMLOCK
Sleep 100
TurnOff VK_CAPITAL
Sleep 100
TurnOff VK_SCROLL
Sleep 500
TurnOn VK_NUMLOCK
TurnOn VK_SCROLL
Sleep 200
TurnOff VK_NUMLOCK
TurnOff VK_SCROLL
Sleep 200
TurnOn VK_NUMLOCK
TurnOn VK_SCROLL
Sleep 200
TurnOff VK_NUMLOCK
TurnOff VK_SCROLL
Sleep 200
TurnOn VK_CAPITAL
Sleep 200
TurnOff VK_CAPITAL
Sleep 200
TurnOn VK_CAPITAL
Sleep 200
TurnOff VK_CAPITAL
Sleep 200
TurnOn VK_NUMLOCK
TurnOn VK_SCROLL
Sleep 200
TurnOff VK_NUMLOCK
TurnOff VK_SCROLL
Sleep 200
TurnOn VK_NUMLOCK
TurnOn VK_SCROLL
Sleep 200
TurnOff VK_NUMLOCK
TurnOff VK_SCROLL
Sleep 200
TurnOn VK_CAPITAL
Sleep 400
TurnOff VK_CAPITAL
Sleep 200
TurnOn VK_NUMLOCK
Sleep 100
TurnOn VK_CAPITAL
Sleep 100
TurnOn VK_SCROLL
Sleep 300
TurnOff VK_SCROLL
Sleep 100
TurnOff VK_CAPITAL
Sleep 100
TurnOff VK_NUMLOCK
Sleep 1000
Unload Me
End Sub
Private Sub TurnOn(vkKey As Long)
'Get the keyboard state
GetKeyboardState kbArray
'Change a key
kbArray.kbByte(vkKey) = 1
'Set the keyboard state
SetKeyboardState kbArray
End Sub
Private Sub TurnOff(vkKey As Long)
'Get the keyboard state
GetKeyboardState kbArray
'change a key
kbArray.kbByte(vkKey) = 0
'set the keyboard state
SetKeyboardState kbArray
End Sub
Private Sub Form_Unload(Cancel As Integer)
'restore the old keyboard state
SetKeyboardState kbOld
End Sub
Last edited by Pirate; Feb 24th, 2004 at 01:42 AM.
-
Feb 23rd, 2004, 08:51 PM
#7
hmm thanks...
I didnt know about the GetKeyState api, I thought I had only the option of calling GetKeyBoardState which makes it a bit more complicated.. anyways I have these two definitions. The first one works, but the second one doesn't. I don't understand why
VB Code:
Private Const VK_CONTROL As Integer = 17
Private Const VK_SHIFT As Integer = 16
' works
Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Integer) As Integer
' raises this error: [b]System.InvalidProgramException:PInvoke item (field,method) must be Static.[/b]
<DllImport("user32")> _
Private Function GetKeyState(ByVal nVirtKey As Integer) As Integer
End Function
anyways, it seems like it returns something positive if the key is up and negative if its down
edit: eeh returns 0 or 1 if the key is up, I think.
Last edited by MrPolite; Feb 23rd, 2004 at 09:08 PM.
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Feb 24th, 2004, 01:41 AM
#8
Sleep mode
Originally posted by MrPolite
' works
Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Integer) As Integer
' raises this error: System.InvalidProgramException:PInvoke item (field,method) must be Static.
<DllImport("user32")> _
Private Function GetKeyState(ByVal nVirtKey As Integer) As Integer
End Function
[/Highlight]
<DllImport> attribute is not required for declaring APIs in VB.NET .
The error raising in the second declaration is mistyped I think . You forgot 'Declare' keyword .
An example for GetKeyState :
VB Code:
'In a module
Public Const WH_KEYBOARD = 2
Public Const VK_SHIFT = &H10
Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, lParam As Any) As Long
Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Public hHook As Long
Public Function KeyboardProc(ByVal idHook As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
'if idHook is less than zero, no further processing is required
If idHook < 0 Then
'call the next hook
KeyboardProc = CallNextHookEx(hHook, idHook, wParam, ByVal lParam)
Else
'check if SHIFT-S is pressed
If (GetKeyState(VK_SHIFT) And &HF0000000) And wParam = Asc("S") Then
'show the result
Form1.Print "Shift-S pressed ..."
End If
'call the next hook
KeyboardProc = CallNextHookEx(hHook, idHook, wParam, ByVal lParam)
End If
End Function
'In a form, called Form1
Private Sub Form_Load()
'KPD-Team 2000
'URL: [url]http://www.allapi.net/[/url]
'set a keyboard hook
hHook = SetWindowsHookEx(WH_KEYBOARD, AddressOf KeyboardProc, App.hInstance, App.ThreadID)
End Sub
Private Sub Form_Unload(Cancel As Integer)
'remove the windows-hook
UnhookWindowsHookEx hHook
End Sub
Parameter info :
· nVirtKey
Specifies a virtual key. If the desired virtual key is a letter or digit (A through Z, a through z, or 0 through 9), nVirtKey must be set to the ASCII value of that character. For other keys, it must be a virtual-key code.
If a non-English keyboard layout is used, virtual keys with values in the range ASCII A through Z and 0 through 9 are used to specify most of the character keys. For example, for the German keyboard layout, the virtual key of value ASCII O (0x4F) refers to the “o” key, whereas VK_OEM_1 refers to the “o with umlaut” key.
Returned Value :
If the function succeeds, the return value specifies the status of the given virtual key. If the high-order bit is 1, the key is down; otherwise, it is up. If the low-order bit is 1, the key is toggled. A key, such as the CAPS LOCK key, is toggled if it is turned on. The key is off and untoggled if the low-order bit is 0. A toggle key’s indicator light (if any) on the keyboard will be on when the key is toggled, and off when the key is untoggled.
And you may need to look up the API 'GetAsyncKeyState' .
-
Jun 21st, 2011, 09:12 AM
#9
New Member
Re: how can I find out if the control key is down?
Better late than never? (VB.Net Express 2010)
if My.Computer.Keyboard.CtrlKeyDown then
' Do Something
end if
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|