Handle keyboard, pointer and drag-and-drop events
Use typed event parameters and ByRef decisions in a small accessible Form.
KeyDown receives a physical key identity and a ByRef Handled flag. The Escape branch clears the input and suppresses default processing. DragEnter defaults to None and accepts only text, explicitly requesting Copy. Drop receives the accepted effect by value. MouseMove reports local device-independent coordinates, not screen coordinates. AllowDrop must be enabled on the target.
Step 1Prepare a safe practice project#
Extract the archive into a new writable folder, separate from your own application. Open InputWorkbench.mcproj in McBasic™. Keep every declared source, layout, resource and migration file together.
To reconstruct it yourself, create a DesktopApp project and add the files declared below. In the complete project, follow these steps as a guided rebuild: replace each named source file once and Check after all its procedures are present.
Exact project configuration
{
"schemaVersion": 1,
"projectId": "mcbasic-web-input-workbench",
"name": "InputWorkbench",
"kind": "DesktopApp",
"language": {
"dialect": "McBasic1",
"requireExplicit": true,
"compare": "Binary",
"defaultArrayBase": 0
},
"application": {
"bundleIdentifier": "org.mcbasic.web.inputworkbench",
"version": "1.0.0",
"buildNumber": "1",
"startupFormId": "main",
"shutdownMode": "OnStartupFormClosed"
},
"forms": [
{
"id": "main",
"typeName": "frmMain",
"layout": "frmMain.form.json",
"code": "frmMain.bas"
}
],
"modules": [],
"classes": [],
"tests": [],
"references": [],
"resources": [],
"targets": [
"osx-arm64"
],
"capabilities": []
}Step 2Build the Form and set its properties#
frmMain
Select the Form first and set its properties. Add containers before their children. These are initial Designer values, not statements to paste into a procedure.
| Form property | Value |
|---|---|
Caption | "Input Workbench" |
Width | 600 |
Height | 330 |
MinWidth | 500 |
MinHeight | 280 |
txtInput · exact Inspector values
| Property | Value |
|---|---|
Left | 24 |
Top | 24 |
Width | 540 |
Height | 110 |
MultiLine | True |
AllowDrop | True |
TabIndex | 0 |
AccessibleName | "Practice text" |
AccessibleDescription | "Type, press Escape to clear, or drop text here." |
| Anchor edges | Left, Top, Right |
lblStatus · exact Inspector values
| Property | Value |
|---|---|
Left | 24 |
Top | 156 |
Width | 540 |
Height | 76 |
Caption | "Type in the field, press Escape, or drag selected text into it." |
WordWrap | True |
AccessibleName | "Input status" |
| Anchor edges | Left, Top, Right |
Step 3Connect the events explicitly#
frmMain
| Object | Event | Procedure | Parameters |
|---|---|---|---|
txtInput | KeyDown | txtInput_KeyDown | KeyDown(ByVal KeyCode As KeyCode, ByVal Shift As KeyModifiers, ByRef Handled As Boolean) |
txtInput | DragEnter | txtInput_DragEnter | DragEnter(ByVal Data As DragData, ByRef Effect As DragEffect, ByVal X As Double, ByVal Y As Double) |
txtInput | Drop | txtInput_Drop | Drop(ByVal Data As DragData, ByVal Effect As DragEffect, ByVal X As Double, ByVal Y As Double) |
lblStatus | MouseMove | lblStatus_MouseMove | MouseMove(ByVal Button As MouseButtons, ByVal Shift As KeyModifiers, ByVal X As Double, ByVal Y As Double) |
Step 4Enter the complete behavior#
Open the named source file. Enter declarations first, then every procedure. Expand a procedure for its full body, or copy the complete file. Helpers are required: do not stop after entering the first Click handler.
frmMain.bas
Enter these declarations at file scope, before the procedures.
Option ExplicitPrivate Sub txtInput_KeyDown(ByVal KeyCode As KeyCode, ByVal Shift As KeyModifiers, ByRef Handled As Boolean)
Enter this helper in the named source file, outside every other procedure. Its callers are included in the same project.
Private Sub txtInput_KeyDown(ByVal KeyCode As KeyCode, ByVal Shift As KeyModifiers, ByRef Handled As Boolean)
If KeyCode = KeyCode.Escape Then
txtInput.Text = ""
lblStatus.Caption = "Escape cleared the field."
Handled = True
End If
End SubPrivate Sub txtInput_DragEnter(ByVal Data As DragData, ByRef Effect As DragEffect, ByVal X As Double, ByVal Y As Double)
Enter this helper in the named source file, outside every other procedure. Its callers are included in the same project.
Private Sub txtInput_DragEnter(ByVal Data As DragData, ByRef Effect As DragEffect, ByVal X As Double, ByVal Y As Double)
Effect = DragEffect.None
If Data.HasText Then Effect = DragEffect.Copy
End SubPrivate Sub txtInput_Drop(ByVal Data As DragData, ByVal Effect As DragEffect, ByVal X As Double, ByVal Y As Double)
Enter this helper in the named source file, outside every other procedure. Its callers are included in the same project.
Private Sub txtInput_Drop(ByVal Data As DragData, ByVal Effect As DragEffect, ByVal X As Double, ByVal Y As Double)
If Not Data.HasText Then Exit Sub
txtInput.Text = Data.Text
lblStatus.Caption = "Text copied by drop at " & CStr(X) & ", " & CStr(Y)
End SubPrivate Sub lblStatus_MouseMove(ByVal Button As MouseButtons, ByVal Shift As KeyModifiers, ByVal X As Double, ByVal Y As Double)
Enter this helper in the named source file, outside every other procedure. Its callers are included in the same project.
Private Sub lblStatus_MouseMove(ByVal Button As MouseButtons, ByVal Shift As KeyModifiers, ByVal X As Double, ByVal Y As Double)
lblStatus.Caption = "Pointer in label: " & CStr(X) & ", " & CStr(Y)
End SubCopy the complete frmMain.bas file
Replace the file once; do not append duplicate procedures.
Option Explicit
Private Sub txtInput_KeyDown(ByVal KeyCode As KeyCode, ByVal Shift As KeyModifiers, ByRef Handled As Boolean)
If KeyCode = KeyCode.Escape Then
txtInput.Text = ""
lblStatus.Caption = "Escape cleared the field."
Handled = True
End If
End Sub
Private Sub txtInput_DragEnter(ByVal Data As DragData, ByRef Effect As DragEffect, ByVal X As Double, ByVal Y As Double)
Effect = DragEffect.None
If Data.HasText Then Effect = DragEffect.Copy
End Sub
Private Sub txtInput_Drop(ByVal Data As DragData, ByVal Effect As DragEffect, ByVal X As Double, ByVal Y As Double)
If Not Data.HasText Then Exit Sub
txtInput.Text = Data.Text
lblStatus.Caption = "Text copied by drop at " & CStr(X) & ", " & CStr(Y)
End Sub
Private Sub lblStatus_MouseMove(ByVal Button As MouseButtons, ByVal Shift As KeyModifiers, ByVal X As Double, ByVal Y As Double)
lblStatus.Caption = "Pointer in label: " & CStr(X) & ", " & CStr(Y)
End SubStep 5Keep resources and storage reproducible#
No external resource or migration files are declared. Any inline migration, seed data or local JSON is present in the code above. Runtime application data and private preferences are not included in the archive.
Step 6Check, run and test the result#
Save all files and run Check. Resolve diagnostics before Run. Developer CLI users can work from the extracted folder:
mcbasic check InputWorkbench.mcproj
mcbasic run InputWorkbench.mcprojAcceptance checklist
- Type text, press Escape and confirm the field clears.
- Move over the label and inspect local pointer coordinates.
- Drag selected text from another application into the input and verify the copied text.
- Try dropping a file: this lesson does not accept file payloads.
- Navigate to the input with Tab and inspect its accessible name.
Step 7Make one change and repeat the tests#
Add a KeyPress handler that reports committed text separately from KeyDown; keep the exact reference signature.
Save a working Git checkpoint first. Change one behavior, Check again and repeat the acceptance checklist. Compare with the downloaded solution if a regression appears.
20f4bfed6b · Build manifest