1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package main
import "core:fmt"
import win "../window"
// Store window pointer globally for the callback
g_window: ^win.Window
main :: proc() {
loop, err := win.create_event_loop()
if err != .None {
fmt.println("Failed to create event loop:", err)
return
}
defer win.destroy_event_loop(loop)
window, err2 := win.create_window(loop, {
title = "Input Test - Press keys to test features",
size = {800, 600},
resizable = true,
visible = true,
decorated = true,
})
if err2 != .None {
fmt.println("Failed to create window:", err2)
return
}
defer win.destroy_window(window)
g_window = window
fmt.println("=== Input Feature Test ===")
fmt.println("Keys:")
fmt.println(" 1-9,0: Change cursor shape")
fmt.println(" H: Toggle hidden cursor")
fmt.println(" C: Toggle confined cursor")
fmt.println(" G: Toggle grabbed cursor")
fmt.println(" R: Toggle raw mouse motion")
fmt.println(" SPACE: Query pressed keys")
fmt.println(" ESC: Exit")
fmt.println()
fmt.printfln("Raw motion supported: %v", win.supports_raw_mouse_motion(loop))
fmt.println()
win.run(loop, proc(event: win.Event, loop: ^win.Event_Loop) -> win.Control_Flow {
window := g_window
#partial switch e in event {
case win.Window_Event_Data:
#partial switch we in e.event {
case win.Close_Requested:
return nil // Exit
case win.Key_Input:
if we.state == .Pressed {
#partial switch we.key {
case .Key_1: win.set_cursor_shape(window, .Arrow); fmt.println("Cursor: Arrow")
case .Key_2: win.set_cursor_shape(window, .IBeam); fmt.println("Cursor: IBeam")
case .Key_3: win.set_cursor_shape(window, .Crosshair); fmt.println("Cursor: Crosshair")
case .Key_4: win.set_cursor_shape(window, .Hand); fmt.println("Cursor: Hand")
case .Key_5: win.set_cursor_shape(window, .Resize_EW); fmt.println("Cursor: Resize_EW")
case .Key_6: win.set_cursor_shape(window, .Resize_NS); fmt.println("Cursor: Resize_NS")
case .Key_7: win.set_cursor_shape(window, .Resize_NWSE); fmt.println("Cursor: Resize_NWSE")
case .Key_8: win.set_cursor_shape(window, .Resize_NESW); fmt.println("Cursor: Resize_NESW")
case .Key_9: win.set_cursor_shape(window, .Resize_All); fmt.println("Cursor: Resize_All")
case .Key_0: win.set_cursor_shape(window, .Not_Allowed); fmt.println("Cursor: Not_Allowed")
case .H:
if win.get_cursor_mode(window) == .Hidden {
win.set_cursor_mode(window, .Normal)
fmt.println("Cursor mode: Normal")
} else {
win.set_cursor_mode(window, .Hidden)
fmt.println("Cursor mode: Hidden")
}
case .C:
if win.get_cursor_mode(window) == .Confined {
win.set_cursor_mode(window, .Normal)
fmt.println("Cursor mode: Normal")
} else {
win.set_cursor_mode(window, .Confined)
fmt.println("Cursor mode: Confined")
}
case .G:
if win.get_cursor_mode(window) == .Grabbed {
win.set_cursor_mode(window, .Normal)
fmt.println("Cursor mode: Normal")
} else {
win.set_cursor_mode(window, .Grabbed)
fmt.println("Cursor mode: Grabbed (press G again to release)")
}
case .R:
raw_enabled := win.is_raw_mouse_motion_enabled(window)
win.set_raw_mouse_motion(window, !raw_enabled)
if !raw_enabled {
fmt.println("Raw mouse motion: ENABLED")
} else {
fmt.println("Raw mouse motion: DISABLED")
}
case .Space:
fmt.println("--- Key State Polling ---")
mods := win.get_modifiers(loop)
fmt.printfln("Modifiers: Shift=%v Ctrl=%v Alt=%v Super=%v",
mods.shift, mods.ctrl, mods.alt, mods.super)
// Check some common keys
if win.is_key_pressed(loop, .W) do fmt.println(" W is pressed")
if win.is_key_pressed(loop, .A) do fmt.println(" A is pressed")
if win.is_key_pressed(loop, .S) do fmt.println(" S is pressed")
if win.is_key_pressed(loop, .D) do fmt.println(" D is pressed")
// Check mouse buttons
if win.is_mouse_button_pressed(loop, .Left) do fmt.println(" Left mouse button pressed")
if win.is_mouse_button_pressed(loop, .Right) do fmt.println(" Right mouse button pressed")
if win.is_mouse_button_pressed(loop, .Middle) do fmt.println(" Middle mouse button pressed")
case .Escape:
return nil // Exit
}
}
}
case win.Device_Event_Data:
#partial switch de in e.event {
case win.Pointer_Motion:
fmt.printfln("Raw motion: dx=%.2f dy=%.2f", de.delta_x, de.delta_y)
}
case win.Loop_Exiting:
fmt.println("Exiting...")
}
return win.Wait{}
})
}