Page 1 of 1
Send keystroke Ctrl+F2 to IDE
Posted: Sun Sep 14, 2025 1:09 pm
by Michael Vogel
I wrote a small
tool which shows all source code marker and added the functionality to remove a marker by invoking Ctrl+F2 from this tool. Anyhow I was not able to do this without activating the IDE window which is not perfect. Any ideas if it is possible to do the same while keeping the IDE window in the background?
Code: Select all
:
:
#SendKeyWait= 120
#SendKeyDelay= 2
i=GetForegroundWindow_(); Marker Tool
m=GetWindowThreadProcessId_(i,0)
n=GetWindowThreadProcessId_(HandleIde,0); IDE
If m<>n
AttachThreadInput_(m,n,#True)
SetForegroundWindow_(HandleIde)
EndIf
Delay(#SendKeyWait)
keybd_event_(#VK_CONTROL,0,0,0)
keybd_event_(#VK_F2,0,0,0)
keybd_event_(#VK_F2,0,#KEYEVENTF_KEYUP,0)
keybd_event_(#VK_CONTROL,0,#KEYEVENTF_KEYUP,0)
If m<>n
AttachThreadInput_(m,n,#False)
SetForegroundWindow_(i)
EndIf
:
:
Re: Send keystroke Ctrl+F2 to IDE
Posted: Sun Sep 14, 2025 3:45 pm
by Axolotl
never tried this, but maybe it is possible like this
Code: Select all
; hwnd = ... ; handle of the IDE Window
; use of SendMessage_() or PostMessage_() and Delay() ??
PostMessage_(hwnd, #WM_KEYDOWN, #VK_CONTROL, #Null) ; lParam probably needs some attention
PostMessage_(hwnd, #WM_KEYDOWN, #VK_F2, #Null) ; -"-
PostMessage_(hwnd, #WM_KEYUP, #VK_CONTROL, #Null) ; -"-
; Borrowed from MSDN.... WM_KEYDOWN
; lParam
; The repeat count, scan code, extended-key flag, context code, previous key-state flag, and transition-state flag, as shown following.
;
; Bits Meaning
; 0-15 The repeat count for the current message. The value is the number of times the keystroke is autorepeated as a result of the user holding down the key. If the keystroke is held long enough, multiple messages are sent. However, the repeat count is not cumulative.
; 16-23 The scan code. The value depends on the OEM.
; 24 Indicates whether the key is an extended key, such as the right-hand ALT and CTRL keys that appear on an enhanced 101- or 102-key keyboard. The value is 1 if it is an extended key; otherwise, it is 0.
; 25-28 Reserved; do not use.
; 29 The context code. The value is always 0 for a WM_KEYDOWN message.
; 30 The previous key state. The value is 1 if the key is down before the message is sent, or it is zero if the key is up.
; 31 The transition state. The value is always 0 For a WM_KEYDOWN message.
Remarks: I guess success depends on how PB-IDE handles key presses.
Re: Send keystroke Ctrl+F2 to IDE
Posted: Sun Sep 14, 2025 4:22 pm
by Michael Vogel
Did not work without the code around it (AttachThreadInput) seen in the snippet above - played around for a while and I fear it isn't possible to do that without a short flicker while the window is active...
One of the following lines have to be used as well to work...
- SetFocus_(Ide\HandleIde) - ok
- SetActiveWindow_(Ide\HandleIde) - ok
- SetForegroundWindow_(Ide\HandleIde) - ok
- PostMessage_(Ide\HandleIde,#WM_SETFOCUS,0,0) - does not work
Re: Send keystroke Ctrl+F2 to IDE
Posted: Mon Sep 15, 2025 12:21 pm
by Axolotl
That's too bad.
Another idea...
Work with the
Scintilla Control and the Markers defined by PB....
You need to 'borrow' the functions from the IDE (github)
The implementation in the IDE is in the following files.
Code: Select all
; Common.pb
; #MARKER_Marker = 22 ; line markers
;
; ScintillaHighlighting.pb
; Procedure AddMarker()
; Procedure ClearMarkers()
; Procedure MarkerJump()
; Procedure.s GetMarkerString() ; get a list of all markers as a string
; Procedure ApplyMarkerString(Markers$) ; apply a string of marker numbers to the file
My simplified get
Scintilla Handle :
Code: Select all
hwnd = FindWindow_(@"WindowClass_2", @"PureBasic 6.21 (x64)")
If hwnd : hwnd = FindWindowEx_(hwnd, #Null, @"PureSplitter", #Null) : EndIf
If hwnd : hwnd = FindWindowEx_(hwnd, #Null, @"PureSplitter", #Null) : EndIf
If hwnd : hwnd = FindWindowEx_(hwnd, #Null, @"PureContainer", #Null) : EndIf
If hwnd : hwnd = FindWindowEx_(hwnd, #Null, @"Scintilla", #Null) : EndIf
If hwnd
Debug "Found PureBasic Scintilla Control == " + hwnd
hwndScintilla = hwnd
EndIf
Re: Send keystroke Ctrl+F2 to IDE
Posted: Mon Sep 15, 2025 6:06 pm
by Michael Vogel
Perfect approach !
THANK YOU!
Everything seems to be so simple (now)...
Code: Select all
#MarkerId=22
If SendMessage_(\HandleScintilla,#SCI_MARKERGET,line-1,0) & (1<<#MarkerId)
n=#SCI_MARKERDELETE
Else
n=#SCI_MARKERADD
EndIf
SendMessage_(\HandleScintilla,n,line-1,#MarkerId)
; or a simple line:
; SendMessage_(\HandleScintilla, #SCI_MARKERADD + Bool(SendMessage_(\HandleScintilla,#SCI_MARKERGET,line-1,0) & (1<<#MarkerId)), line-1, #MarkerId)
The result can be seen in the 'Jump to Marker' tool
here...