Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 5th, 2003, 09:10 PM
dewolla dewolla is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 2 dewolla User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Exclamation sending ctrl keystroke in VB

I am trying to send the keystroke for the control key in VB,
sendkeys as far as I can see dosn't let you just have the ctrl key. The reason for this is that I have a KVM that switches with a ctrl crtl on the keyboard, and I want to simulate this.

Reply With Quote
  #2  
Old November 5th, 2003, 11:06 PM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via MSN to cleverpig
U can use hotkey to replace "sendkey" function.U may custom a hotkey on the keyboard to call some function!
A hotkey is a key combination that you can use to trigger an action anywhere in Windows.
When the form loads, use the RegisterHotKey API function to install the hotkey (in this example, Alt-F10). Then subclass to watch for the WM_HOTKEY message.



Private Sub Form_Load()
' Register the hotkey.
If RegisterHotKey(hWnd, HOTKEY_ID, _
MOD_ALT, VK_F10) = 0 _
Then
MsgBox "Error registering hotkey."
Unload Me
End If

' Subclass the TextBox to watch for
' WM_HOTKEY messages.
OldWindowProc = SetWindowLong( _
hWnd, GWL_WNDPROC, _
AddressOf NewWindowProc)
End Sub



When the new WindowProc sees the WM_HOTKEY message, it calls the form's public Hotkey subroutine.


' Look for the WM_HOTKEY message.
Public Function NewWindowProc(ByVal hWnd As Long, ByVal Msg _
As Long, ByVal wParam As Long, ByVal lParam As Long) As _
Long
Const WM_NCDESTROY = &H82
Const WM_HOTKEY = &H312

' If we're being destroyed,
' restore the original WindowProc and
' unregister the hotkey.
If Msg = WM_NCDESTROY Then
SetWindowLong _
hWnd, GWL_WNDPROC, _
OldWindowProc

UnregisterHotKey hWnd, HOTKEY_ID
End If

' See if this is the WM_HOTKEY message.
If Msg = WM_HOTKEY Then Form1.Hotkey

' Process the message normally.
NewWindowProc = CallWindowProc( _
OldWindowProc, hWnd, Msg, wParam, _
lParam)
End Function



When the program receives the Hotkey event, it uses the GetForegroundWindow API function to find the window in the foreground. It then call SetWindowPlacement to minimize the window.


' We got the hotkey.
Public Sub Hotkey()
Dim active_hwnd As Long
Dim wp As WINDOWPLACEMENT

' Get the active window's handle.
active_hwnd = GetForegroundWindow()

' Get the window's current placement information.
wp.length = Len(wp)
GetWindowPlacement active_hwnd, wp

' Minimize it.
wp.showCmd = SW_SHOWMINIMIZED

' Perform the action.
SetWindowPlacement active_hwnd, wp
End Sub

Reply With Quote
  #3  
Old November 6th, 2003, 12:22 AM
dewolla dewolla is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 2 dewolla User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
hotkey

I'm not sure thats what I'm looking for.
Here are more specifics of what I'm trying to do, I want my app to send the keystrokes , ctrl ctrl, when the mouse touches the edge of the screen, since sendkey doesn't have an option to just send the ctrl key, only crtl+something else I cannot use sendkey, Hotkey seems to create a keystroke listener from which an action can be taken, but my listener is a mouse listener and the action is the keystroke.
How would you use hotkeys to send out a keystroke?
Any Ideas?

Reply With Quote
  #4  
Old November 6th, 2003, 01:48 AM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via MSN to cleverpig
I have known your meaning.U can use win32api "Sendinput".This api can realize this function:The SendInput function synthesizes keystrokes, mouse motions, and button clicks!This is the detailed information about it:
Decalration:
Declare Function SendInput Lib "user32.dll" (ByVal nInputs As Long, pInputs As GENERALINPUT, ByVal cbSize As Long) As Long

Parameters:
?nInputs
[in] Specifies the number of structures in the pInputs array.

?pInputs
[in] Pointer to an array of INPUT structures. Each structure represents an event to be inserted into the keyboard or mouse input stream.

?cbSize
[in] Specifies the size, in bytes, of an INPUT structure. If cbSize is not the size of an INPUT structure, the function will fail.

Return Value:
The function returns the number of events that it successfully inserted into the keyboard or mouse input stream. If the function returns zero, the input was already blocked by another thread.

To get extended error information, call GetLastError.

Sample:
Const VK_H = 72
Const VK_E = 69
Const VK_L = 76
Const VK_O = 79
Const KEYEVENTF_KEYUP = &H2
Const INPUT_MOUSE = 0
Const INPUT_KEYBOARD = 1
Const INPUT_HARDWARE = 2
Private Type MOUSEINPUT
dx As Long
dy As Long
mouseData As Long
dwFlags As Long
time As Long
dwExtraInfo As Long
End Type
Private Type KEYBDINPUT
wVk As Integer
wScan As Integer
dwFlags As Long
time As Long
dwExtraInfo As Long
End Type
Private Type HARDWAREINPUT
uMsg As Long
wParamL As Integer
wParamH As Integer
End Type
Private Type GENERALINPUT
dwType As Long
xi(0 To 23) As Byte
End Type
Private Declare Function SendInput Lib "user32.dll" (ByVal nInputs As Long, pInputs As GENERALINPUT, ByVal cbSize As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)
Private Sub Form_KeyPress(KeyAscii As Integer)
'Print the key on the form
Me.Print Chr$(KeyAscii);
End Sub
Private Sub Form_Paint()
'KPD-Team 2000
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
'Clear the form
Me.Cls
'call the SendKey-function
SendKey VK_H
SendKey VK_E
SendKey VK_L
SendKey VK_L
SendKey VK_O
End Sub
Private Sub SendKey(bKey As Byte)
Dim GInput(0 To 1) As GENERALINPUT
Dim KInput As KEYBDINPUT
KInput.wVk = bKey 'the key we're going to press
KInput.dwFlags = 0 'press the key
'copy the structure into the input array's buffer.
GInput(0).dwType = INPUT_KEYBOARD ' keyboard input
CopyMemory GInput(0).xi(0), KInput, Len(KInput)
'do the same as above, but for releasing the key
KInput.wVk = bKey ' the key we're going to realease
KInput.dwFlags = KEYEVENTF_KEYUP ' release the key
GInput(1).dwType = INPUT_KEYBOARD ' keyboard input
CopyMemory GInput(1).xi(0), KInput, Len(KInput)
'send the input now
Call SendInput(2, GInput(0), Len(GInput(0)))
End Sub

U can visit http://www.allapi.net/ and down API-Guide contained all content.

Reply With Quote
  #5  
Old November 12th, 2003, 12:21 PM
easy easy is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 16 easy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 32 m 15 sec
Reputation Power: 0
to send the ctrl key, it's "^", so ctrl R would be "^R"

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > sending ctrl keystroke in VB


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway