Deprecated: The behavior of unparenthesized expressions containing both '.' and '+'/'-' will change in PHP 8: '+'/'-' will take a higher precedence in /home/iano/public_html/tpforums-vb5/forum/includes/class_core.php on line 5842

PHP Warning: Use of undefined constant MYSQL_NUM - assumed 'MYSQL_NUM' (this will throw an Error in a future version of PHP) in ..../includes/init.php on line 165

PHP Warning: Use of undefined constant MYSQL_ASSOC - assumed 'MYSQL_ASSOC' (this will throw an Error in a future version of PHP) in ..../includes/init.php on line 165

PHP Warning: Use of undefined constant MYSQL_BOTH - assumed 'MYSQL_BOTH' (this will throw an Error in a future version of PHP) in ..../includes/init.php on line 165

PHP Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in ..../includes/functions_navigation.php on line 588

PHP Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in ..../includes/functions_navigation.php on line 612

PHP Warning: Use of undefined constant archive_postsperpage - assumed 'archive_postsperpage' (this will throw an Error in a future version of PHP) in ..../archive/index.php on line 456
Send Message help. [Archive] - Forums

PDA

View Full Version : Send Message help.



Kannibale
10-17-2013, 04:02 PM
Okay this is what I have..


Public Shared Tibia As Process = Process.GetProcessesByName("Tibia")(0)

Private Declare Ansi Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As IntPtr, ByVal lParam As Integer) As IntPtr

Const WM_KEYDOWN = &H100
Const WM_KEYUP = &H101
Const GW_CHILD As Long = 5
Const WM_CHAR = 258
Const VK_F10 = &H79
Const VK_F5 = &H74
Const VK_L = &H4C
Const WM_SETTEXT = 12

Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
SendMessage(Tibia.MainWindowHandle, WM_CHAR, VK_L, 0)
End Sub

It seems to work perfectly using WM_CHAR to send single characters to the client but if I try to use WM_KEYDOWN and then WM_KEYUP, nothing gets sent to the client..


SendMessage(Tibia.MainWindowHandle, WM_KEYDOWN, VK_L, 0)
SendMessage(Tibia.MainWindowHandle, WM_KEYUP, VK_L, 0)

^ Doesn't seem to work. Any thoughts why?

Kannibale
10-17-2013, 04:14 PM
Figured it out nevermind

jo3bingham
10-17-2013, 04:49 PM
Please supply your fix for others who may have the same problem; give back to the community.

Kannibale
10-24-2013, 12:14 AM
Please supply your fix for others who may have the same problem; give back to the community.

It's not really hard to figure out. This is more than enough to get a person what they need. There is a difference between giving back and spoon feeding.

XtrmJash
10-24-2013, 06:21 AM
It's not really hard to figure out. This is more than enough to get a person what they need. There is a difference between giving back and spoon feeding.

I think the comment was more concerning your lack of an answer to the original question. For example, if someone were to come here and see this code, they might try to use it. Upon doing so they would encounter the exact same problem that you did. Due to the current amount of information on this thread, they would be left with some code that doesn't quite work, and a thread which doesn't explain why.

So, could you please post at least the concept of what was wrong with the original code?

Ash Katchup
10-25-2013, 08:00 PM
To send a string, i use the following code.

I can't remember why i subtract "0x20" from the ASCII code. But, i was getting problems with the code and read that solution on an article.



public void SendText(string stext)
{
byte[] array_ascci = Encoding.ASCII.GetBytes(stext);

foreach (byte b in array_ascci)
{
SendMessage(WindowHandle, WM_KEYDOWN, b - 0x20, 0);
SendMessage(WindowHandle, WM_CHAR, b, 0);
SendMessage(WindowHandle, WM_KEYUP, b - 0x20, 0);
}

//Send a RETURN / ENTER (code = 0xD)
SendMessage(WindowHandle, WM_KEYDOWN, 0xD, 0);
SendMessage(WindowHandle, WM_CHAR, 0xD, 0);
SendMessage(WindowHandle, WM_KEYUP, 0xD, 0);

}


And to send a hotkey, i use the following code:



public void SendHotkey(System.Windows.Forms.Keys hotkey)
{
SendMessage(WindowHandle, WM_KEYDOWN, (int)hotkey, 0);
SendMessage(WindowHandle, WM_KEYUP, (int)hotkey, 0);
}


Constants:



public const uint WM_KEYDOWN = 0x100;
public const uint WM_KEYUP = 0x101;
public const uint WM_CHAR = 0x102;

Farsa
10-25-2013, 08:07 PM
To send a string, i use the following code.

I can't remember why i subtract "0x20" from the ASCII code. But, i was getting problems with the code and read that solution on an article.


I bet it is related to the fact that "actual" characters start from 0x20 on the ascii table

Ash Katchup
10-26-2013, 07:10 PM
I bet it is related to the fact that "actual" characters start from 0x20 on the ascii table

That makes sense...