-
Apr 9th, 2021, 07:31 PM
#1
WndProc for console applications??
Hi,
Just wondering how we can WndProc for console applications?
I want to capture some key events that I cannot by other means.
Thanks in advance,
Kris
-
Apr 9th, 2021, 07:39 PM
#2
Re: WndProc for console applications??
How about this: https://docs.microsoft.com/en-us/dot...tframework-2.0
I've used it on an old media player I made in 2011 but I guess it is still valid but you have to have a continues loop.
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Apr 9th, 2021, 08:06 PM
#3
Re: WndProc for console applications??
As I stated in the OP: "cannot by other means" ...
The key combinations I want to capture do not trigger the standard key events!
-
Apr 9th, 2021, 09:42 PM
#4
Re: WndProc for console applications??
Does the Console window expose a Handle? Look at extending NativeWindow, which can have a wndProc
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Apr 9th, 2021, 10:59 PM
#5
Re: WndProc for console applications??
Yes ... I just tried this and it doesn't seem to work (GetConsoleWindow) below:
VB.Net Code:
Imports System.Runtime.InteropServices
Imports System.Windows.Forms
Public Class Module1
Shared Sub Main()
Application.AddMessageFilter(New Intercept)
'Console.WriteLine($"{GetConsoleWindow()}")
Console.WriteLine($"{Process.GetCurrentProcess().MainWindowHandle}")
Console.WriteLine("asd")
Console.WriteLine("asd2")
Console.ReadLine()
End Sub
End Class
Public Class Intercept
Inherits NativeWindow
Implements IMessageFilter
<DllImport("kernel32.dll")>
Private Shared Function GetConsoleWindow() As IntPtr
End Function
Public Sub New()
AssignHandle(GetConsoleWindow())
End Sub
Public Function PreFilterMessage(ByRef m As Message) As Boolean Implements IMessageFilter.PreFilterMessage
Debug.Print(m.ToString())
Return False
End Function
End Class
-
Apr 9th, 2021, 11:06 PM
#6
Re: WndProc for console applications??
As this seems like a application keyboard scan , I will send you a PM because I don't want people take advantage and start scanning apps.
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Apr 9th, 2021, 11:41 PM
#7
Re: WndProc for console applications??
Originally Posted by sapator
As this seems like a application keyboard scan , I will send you a PM because I don't want people take advantage and start scanning apps.
@sapator - Can you also send it to me? Thanks
@ioo - I think the problem with wndProc, is that it is designed for Windows.Forms, and the Console is a completely different type of window...
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Apr 9th, 2021, 11:45 PM
#8
Re: WndProc for console applications??
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Apr 9th, 2021, 11:54 PM
#9
Re: WndProc for console applications??
Hrm.. I really didn't want to use keyboard hooks for two reasons:
- I have seen virus scanners pick any keyboard hook up as a virus
- I am doing A LOT of extending of the console and will probably require this for something else later anyway
What I actually want it for in this specific case is to capture a copy (which this way I could probably capture from the context menus copy also somehow this way) ...
When you have selected text, the Ctrl+C will never be passed to the Console.ReadKey etc ... Also using that would mean that it will only work when "reading" anyway ... not if it's processing!
My goal is to copy formatted text as well as the plain text, so it can be copied with coloring etc into Word etc.
I can get the selected area with GetConsoleSelectionInfo(), translate the points, and then use ReadConsoleOutput(), to get the text... this is all that is missing :P
-
Apr 10th, 2021, 12:39 AM
#10
Re: WndProc for console applications??
To monitor the clipboard for changes... This might work in a console app.
https://www.vbforums.com/showthread....rd-for-changes
Same problem though, as it’s intended for winforms
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Apr 10th, 2021, 04:59 PM
#11
Re: WndProc for console applications??
That seems a bit dodge and won't work anyway...
I need to get the selected text, and when you copy the selection has already cleared; I need the selection to get the formatted selection from the console!
I am sure that this must be somehow possible?
-
Apr 12th, 2021, 07:06 PM
#12
Re: WndProc for console applications??
-
Apr 12th, 2021, 07:07 PM
#13
Re: WndProc for console applications??
what i wrote got lost 3 time sby this forum. meh so links it is
-
Apr 19th, 2021, 06:56 PM
#14
Re: WndProc for console applications??
Originally Posted by ident
Are you saying that it uses a message only window and can't be captured?
Also as stated clipboard monitoring will not work, since I need the selection area from the console, by the time it has been copied it has already been deselected!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|