PDA

Click to See Complete Forum and Search --> : Mouse & keyboard


sachinsugandhi
Mar 4th, 2001, 01:16 PM
Hello to all of you,
I want to know whether i can restict the mouse movement in an particular are or not if yes how.
Also how can i get which key has been pressed in any window ,even if i get any key has been pressed (not which )will also be sufficient.Thanks for reading & repling
my question.

AndySoft
Mar 4th, 2001, 03:53 PM
Well, I can't think of anything for the Mouse question, but for the Keyboard just use the KeyPress event and put it into all the forms your program uses.

Mar 4th, 2001, 06:07 PM
To restrict the mouse to a specific area, use the ClipCursor function.

Private Declare Function ClipCursor Lib "user32" (lpRect As RECT) As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long

Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Sub RestrictMouse()
Dim RC As RECT
GetWindowRect hwnd, RC
ClipCursor RC
End Sub

Sub UnRestrictMouse()
Dim RC As RECT
GetWindowRect GetDesktopWindow, RC
ClipCursor RC
End Sub

Private Sub Command1_Click()
RestrictMouse
End Sub

Private Sub Form_Unload(Cancel As Integer)
UnRestrictMouse
End Sub

sachinsugandhi
Mar 6th, 2001, 04:06 AM
Thank you Megatron for your code but their is some more problem,that code works fine when the program is runned through vb itself but it fails by giving the message that "The program has done some illegal operation",when an exe is made of the program, so please tell me where is the fault in my code or in my windows.

sachinsugandhi
Mar 6th, 2001, 04:17 AM
Thank you for replying andysoft but my problem was something else i.e. i wanted to check key press event for all the other softwares which are working at this time which may be any one of notepad wordpad etc.so please reply for it.

Mar 6th, 2001, 02:34 PM
I'm not sure why you'd be getting an illegal operation. Do you have any other code in your Form? It's possible that it might be that code that is causing the conflicts.