4 Replies - 3368 Views - Last Post: 19 April 2009 - 09:19 AM Rate Topic: -----

#1 Joshdw  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 225
  • Joined: 23-March 09

Help with SendKeys

Posted 11 April 2009 - 08:51 AM

Hello i really need help with this code:
I have made this project, it has a textbox and a button. When you click the button i need the sendkeys.send("text from the textbox") send so it should be like this :

Sendkeys.send("[color=blue]")
Sendkeys.send("The first letter of the textbox")
Sendkeys.send("[/color]")

'if there is more than 1 letter it will do the following

Sendkeys.send("[color=green]")
Sendkeys.send("The secound letter of the textbox")
Sendkeys.send("[/color]")
Sendkeys.send("[color=pink]")
Sendkeys.send("The third letter of the textbox")
Sendkeys.send("[/color]")
Sendkeys.send("[color=purple]")
Sendkeys.send("The thourth letter of the textbox")
Sendkeys.send("[/color]")


Does anyone know how i could make it do that, so that every letter it finds, makes it change the sendkeys.send([color=colorname])? And that if theres more than 1 letter it continues doing it?
Additional info: i making this for a SHOUTBOX, so it basicly a shoutbox talker that goes in a rainbow color.
THanks in advanced

EDIT: Title edited to be more descriptive

PsychoCoder :)

Is This A Good Question/Topic? 0
  • +

Replies To: Help with SendKeys

#2 Joshdw  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 225
  • Joined: 23-March 09

Re: Help with SendKeys

Posted 11 April 2009 - 03:11 PM

could the LEN feature maybe help?
Was This Post Helpful? 0
  • +
  • -

#3 microstoc  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 59
  • Joined: 04-April 09

Re: Help with SendKeys

Posted 11 April 2009 - 03:51 PM

View PostJoshdw, on 11 Apr, 2009 - 07:51 AM, said:

Hello i really need help with this code:
I have made this project, it has a textbox and a button. When you click the button i need the sendkeys.send("text from the textbox") send so it should be like this :

Sendkeys.send("[color=blue]")
Sendkeys.send("The first letter of the textbox")
Sendkeys.send("[/color]")

'if there is more than 1 letter it will do the following

Sendkeys.send("[color=green]")
Sendkeys.send("The secound letter of the textbox")
Sendkeys.send("[/color]")
Sendkeys.send("[color=pink]")
Sendkeys.send("The third letter of the textbox")
Sendkeys.send("[/color]")
Sendkeys.send("[color=purple]")
Sendkeys.send("The thourth letter of the textbox")
Sendkeys.send("[/color]")


Does anyone know how i could make it do that, so that every letter it finds, makes it change the sendkeys.send([color=colorname])? And that if theres more than 1 letter it continues doing it?
Additional info: i making this for a SHOUTBOX, so it basicly a shoutbox talker that goes in a rainbow color.
THanks in advanced



I can do it in a RichTextBox.


'color the chars in richtextbox1
'put your text in richtextbox1

Dim Pno As Integer
Dim Counter As Integer = 0

For Pno = 1 To Richtextbox1.Text.Length

	'select a single character
	Me.RichTextBox1.Selectionstart = Pno
	Me.RichTextBox1.SelectionLength = 1

	'assign a color to the character according to a counter value

	Counter = Counter + 1

	'reset the counter if it exceeds our number of color choices
	If (Counter = 6) Then Counter = 1

	'assign a color to the selected text
	If (Counter = 1) Then Me.RichTextBox1.SelectionColor = Color.Red
	If (Counter = 2) Then Me.RichTextBox1.SelectionColor = Color.Green
	If (Counter = 3) Then Me.RichTextBox1.SelectionColor = Color.Blue
	If (Counter = 4) Then Me.RichTextBox1.SelectionColor = Color.Yellow
	If (Counter = 5) Then Me.RichTextBox1.SelectionColor = Color.Orange

Next



Was This Post Helpful? 0
  • +
  • -

#4 Joshdw  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 225
  • Joined: 23-March 09

Re: Help with SendKeys

Posted 18 April 2009 - 08:19 AM

Hmm its not really what im looking for :/
Was This Post Helpful? 0
  • +
  • -

#5 LemonMan  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 15
  • View blog
  • Posts: 170
  • Joined: 22-August 05

Re: Help with SendKeys

Posted 19 April 2009 - 09:19 AM

I think this is what you want.

		Dim termColor As String = "[/color]"
		Dim startColor1 As String = "[color="
		Dim startColor2 As String = "]"

		Dim myColors As New List(Of String)

		myColors.Add("blue")
		myColors.Add("green")
		myColors.Add("pink")
		myColors.Add("purple")

		TextBox1.Text = TextBox1.Text.Trim

		Dim intTextLength As Integer = TextBox1.Text.Length

		If intTextLength = 1 Then
			SendKeys.Send(startColor1 & myColors(0) & startColor2 & ControlChars.NewLine)
			SendKeys.Send(TextBox1.Text & ControlChars.NewLine)
			SendKeys.Send(termColor & ControlChars.NewLine)
		Else
			For intPos As Integer = 0 To (intTextLength - 1)
				SendKeys.Send(startColor1 & myColors(intPos) & startColor2 & ControlChars.NewLine)
				SendKeys.Send(TextBox1.Text(intPos) & ControlChars.NewLine)
				SendKeys.Send(termColor & ControlChars.NewLine)
			Next
		End If



By the way, if this doesn't work, it's because you are not setting focus to the correct window where you want the keyboard input to be inserted. To set focus, you need to get the handle of the window and use some API calls to focus it.

This post has been edited by LemonMan: 19 April 2009 - 09:19 AM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1