diff options
Diffstat (limited to 'contrib/glfw/glfw-3.3.5.bin.WIN64/docs/html/input_guide.html')
-rw-r--r-- | contrib/glfw/glfw-3.3.5.bin.WIN64/docs/html/input_guide.html | 560 |
1 files changed, 560 insertions, 0 deletions
diff --git a/contrib/glfw/glfw-3.3.5.bin.WIN64/docs/html/input_guide.html b/contrib/glfw/glfw-3.3.5.bin.WIN64/docs/html/input_guide.html new file mode 100644 index 0000000..81d3518 --- /dev/null +++ b/contrib/glfw/glfw-3.3.5.bin.WIN64/docs/html/input_guide.html | |||
@@ -0,0 +1,560 @@ | |||
1 | <!DOCTYPE html> | ||
2 | <html lang="en"> | ||
3 | <head> | ||
4 | <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> | ||
5 | <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
6 | <meta http-equiv="X-UA-Compatible" content="IE=9"/> | ||
7 | <meta name="generator" content="Doxygen 1.9.2"/> | ||
8 | <title>GLFW: Input guide</title> | ||
9 | <link href="tabs.css" rel="stylesheet" type="text/css"/> | ||
10 | <script type="text/javascript" src="jquery.js"></script> | ||
11 | <script type="text/javascript" src="dynsections.js"></script> | ||
12 | <link href="search/search.css" rel="stylesheet" type="text/css"/> | ||
13 | <script type="text/javascript" src="search/searchdata.js"></script> | ||
14 | <script type="text/javascript" src="search/search.js"></script> | ||
15 | <link href="doxygen.css" rel="stylesheet" type="text/css" /> | ||
16 | <link href="extra.css" rel="stylesheet" type="text/css"/> | ||
17 | </head> | ||
18 | <body> | ||
19 | <div id="top"><!-- do not remove this div, it is closed by doxygen! --> | ||
20 | <div id="titlearea"> | ||
21 | <div class="glfwheader"> | ||
22 | <a href="https://www.glfw.org/" id="glfwhome">GLFW</a> | ||
23 | <ul class="glfwnavbar"> | ||
24 | <li><a href="https://www.glfw.org/documentation.html">Documentation</a></li> | ||
25 | <li><a href="https://www.glfw.org/download.html">Download</a></li> | ||
26 | <li><a href="https://www.glfw.org/community.html">Community</a></li> | ||
27 | </ul> | ||
28 | </div> | ||
29 | </div> | ||
30 | <!-- end header part --> | ||
31 | <!-- Generated by Doxygen 1.9.2 --> | ||
32 | <script type="text/javascript"> | ||
33 | /* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */ | ||
34 | var searchBox = new SearchBox("searchBox", "search",'Search','.html'); | ||
35 | /* @license-end */ | ||
36 | </script> | ||
37 | <script type="text/javascript" src="menudata.js"></script> | ||
38 | <script type="text/javascript" src="menu.js"></script> | ||
39 | <script type="text/javascript"> | ||
40 | /* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */ | ||
41 | $(function() { | ||
42 | initMenu('',true,false,'search.php','Search'); | ||
43 | $(document).ready(function() { init_search(); }); | ||
44 | }); | ||
45 | /* @license-end */ | ||
46 | </script> | ||
47 | <div id="main-nav"></div> | ||
48 | <!-- window showing the filter options --> | ||
49 | <div id="MSearchSelectWindow" | ||
50 | onmouseover="return searchBox.OnSearchSelectShow()" | ||
51 | onmouseout="return searchBox.OnSearchSelectHide()" | ||
52 | onkeydown="return searchBox.OnSearchSelectKey(event)"> | ||
53 | </div> | ||
54 | |||
55 | <!-- iframe showing the search results (closed by default) --> | ||
56 | <div id="MSearchResultsWindow"> | ||
57 | <iframe src="javascript:void(0)" frameborder="0" | ||
58 | name="MSearchResults" id="MSearchResults"> | ||
59 | </iframe> | ||
60 | </div> | ||
61 | |||
62 | </div><!-- top --> | ||
63 | <div><div class="header"> | ||
64 | <div class="headertitle"><div class="title">Input guide </div></div> | ||
65 | </div><!--header--> | ||
66 | <div class="contents"> | ||
67 | <div class="toc"><h3>Table of Contents</h3> | ||
68 | <ul><li class="level1"><a href="#events">Event processing</a></li> | ||
69 | <li class="level1"><a href="#input_keyboard">Keyboard input</a><ul><li class="level2"><a href="#input_key">Key input</a></li> | ||
70 | <li class="level2"><a href="#input_char">Text input</a></li> | ||
71 | <li class="level2"><a href="#input_key_name">Key names</a></li> | ||
72 | </ul> | ||
73 | </li> | ||
74 | <li class="level1"><a href="#input_mouse">Mouse input</a><ul><li class="level2"><a href="#cursor_pos">Cursor position</a></li> | ||
75 | <li class="level2"><a href="#cursor_mode">Cursor mode</a></li> | ||
76 | <li class="level2"><a href="#raw_mouse_motion">Raw mouse motion</a></li> | ||
77 | <li class="level2"><a href="#cursor_object">Cursor objects</a><ul><li class="level3"><a href="#cursor_custom">Custom cursor creation</a></li> | ||
78 | <li class="level3"><a href="#cursor_standard">Standard cursor creation</a></li> | ||
79 | <li class="level3"><a href="#cursor_destruction">Cursor destruction</a></li> | ||
80 | <li class="level3"><a href="#cursor_set">Cursor setting</a></li> | ||
81 | </ul> | ||
82 | </li> | ||
83 | <li class="level2"><a href="#cursor_enter">Cursor enter/leave events</a></li> | ||
84 | <li class="level2"><a href="#input_mouse_button">Mouse button input</a></li> | ||
85 | <li class="level2"><a href="#scrolling">Scroll input</a></li> | ||
86 | </ul> | ||
87 | </li> | ||
88 | <li class="level1"><a href="#joystick">Joystick input</a><ul><li class="level2"><a href="#joystick_axis">Joystick axis states</a></li> | ||
89 | <li class="level2"><a href="#joystick_button">Joystick button states</a></li> | ||
90 | <li class="level2"><a href="#joystick_hat">Joystick hat states</a></li> | ||
91 | <li class="level2"><a href="#joystick_name">Joystick name</a></li> | ||
92 | <li class="level2"><a href="#joystick_userptr">Joystick user pointer</a></li> | ||
93 | <li class="level2"><a href="#joystick_event">Joystick configuration changes</a></li> | ||
94 | <li class="level2"><a href="#gamepad">Gamepad input</a></li> | ||
95 | <li class="level2"><a href="#gamepad_mapping">Gamepad mappings</a></li> | ||
96 | </ul> | ||
97 | </li> | ||
98 | <li class="level1"><a href="#time">Time input</a></li> | ||
99 | <li class="level1"><a href="#clipboard">Clipboard input and output</a></li> | ||
100 | <li class="level1"><a href="#path_drop">Path drop input</a></li> | ||
101 | </ul> | ||
102 | </div> | ||
103 | <div class="textblock"><p >This guide introduces the input related functions of GLFW. For details on a specific function in this category, see the <a class="el" href="group__input.html">Input reference</a>. There are also guides for the other areas of GLFW.</p> | ||
104 | <ul> | ||
105 | <li><a class="el" href="intro_guide.html">Introduction to the API</a></li> | ||
106 | <li><a class="el" href="window_guide.html">Window guide</a></li> | ||
107 | <li><a class="el" href="context_guide.html">Context guide</a></li> | ||
108 | <li><a class="el" href="vulkan_guide.html">Vulkan guide</a></li> | ||
109 | <li><a class="el" href="monitor_guide.html">Monitor guide</a></li> | ||
110 | </ul> | ||
111 | <p >GLFW provides many kinds of input. While some can only be polled, like time, or only received via callbacks, like scrolling, many provide both callbacks and polling. Callbacks are more work to use than polling but is less CPU intensive and guarantees that you do not miss state changes.</p> | ||
112 | <p >All input callbacks receive a window handle. By using the <a class="el" href="window_guide.html#window_userptr">window user pointer</a>, you can access non-global structures or objects from your callbacks.</p> | ||
113 | <p >To get a better feel for how the various events callbacks behave, run the <code>events</code> test program. It register every callback supported by GLFW and prints out all arguments provided for every event, along with time and sequence information.</p> | ||
114 | <h1><a class="anchor" id="events"></a> | ||
115 | Event processing</h1> | ||
116 | <p >GLFW needs to poll the window system for events both to provide input to the application and to prove to the window system that the application hasn't locked up. Event processing is normally done each frame after <a class="el" href="window_guide.html#buffer_swap">buffer swapping</a>. Even when you have no windows, event polling needs to be done in order to receive monitor and joystick connection events.</p> | ||
117 | <p >There are three functions for processing pending events. <a class="el" href="group__window.html#ga37bd57223967b4211d60ca1a0bf3c832">glfwPollEvents</a>, processes only those events that have already been received and then returns immediately.</p> | ||
118 | <div class="fragment"><div class="line"><a class="code hl_function" href="group__window.html#ga37bd57223967b4211d60ca1a0bf3c832">glfwPollEvents</a>();</div> | ||
119 | <div class="ttc" id="agroup__window_html_ga37bd57223967b4211d60ca1a0bf3c832"><div class="ttname"><a href="group__window.html#ga37bd57223967b4211d60ca1a0bf3c832">glfwPollEvents</a></div><div class="ttdeci">void glfwPollEvents(void)</div><div class="ttdoc">Processes all pending events.</div></div> | ||
120 | </div><!-- fragment --><p >This is the best choice when rendering continuously, like most games do.</p> | ||
121 | <p >If you only need to update the contents of the window when you receive new input, <a class="el" href="group__window.html#ga554e37d781f0a997656c26b2c56c835e">glfwWaitEvents</a> is a better choice.</p> | ||
122 | <div class="fragment"><div class="line"><a class="code hl_function" href="group__window.html#ga554e37d781f0a997656c26b2c56c835e">glfwWaitEvents</a>();</div> | ||
123 | <div class="ttc" id="agroup__window_html_ga554e37d781f0a997656c26b2c56c835e"><div class="ttname"><a href="group__window.html#ga554e37d781f0a997656c26b2c56c835e">glfwWaitEvents</a></div><div class="ttdeci">void glfwWaitEvents(void)</div><div class="ttdoc">Waits until events are queued and processes them.</div></div> | ||
124 | </div><!-- fragment --><p >It puts the thread to sleep until at least one event has been received and then processes all received events. This saves a great deal of CPU cycles and is useful for, for example, editing tools.</p> | ||
125 | <p >If you want to wait for events but have UI elements or other tasks that need periodic updates, <a class="el" href="group__window.html#ga605a178db92f1a7f1a925563ef3ea2cf">glfwWaitEventsTimeout</a> lets you specify a timeout.</p> | ||
126 | <div class="fragment"><div class="line"><a class="code hl_function" href="group__window.html#ga605a178db92f1a7f1a925563ef3ea2cf">glfwWaitEventsTimeout</a>(0.7);</div> | ||
127 | <div class="ttc" id="agroup__window_html_ga605a178db92f1a7f1a925563ef3ea2cf"><div class="ttname"><a href="group__window.html#ga605a178db92f1a7f1a925563ef3ea2cf">glfwWaitEventsTimeout</a></div><div class="ttdeci">void glfwWaitEventsTimeout(double timeout)</div><div class="ttdoc">Waits with timeout until events are queued and processes them.</div></div> | ||
128 | </div><!-- fragment --><p >It puts the thread to sleep until at least one event has been received, or until the specified number of seconds have elapsed. It then processes any received events.</p> | ||
129 | <p >If the main thread is sleeping in <a class="el" href="group__window.html#ga554e37d781f0a997656c26b2c56c835e">glfwWaitEvents</a>, you can wake it from another thread by posting an empty event to the event queue with <a class="el" href="group__window.html#gab5997a25187e9fd5c6f2ecbbc8dfd7e9">glfwPostEmptyEvent</a>.</p> | ||
130 | <div class="fragment"><div class="line"><a class="code hl_function" href="group__window.html#gab5997a25187e9fd5c6f2ecbbc8dfd7e9">glfwPostEmptyEvent</a>();</div> | ||
131 | <div class="ttc" id="agroup__window_html_gab5997a25187e9fd5c6f2ecbbc8dfd7e9"><div class="ttname"><a href="group__window.html#gab5997a25187e9fd5c6f2ecbbc8dfd7e9">glfwPostEmptyEvent</a></div><div class="ttdeci">void glfwPostEmptyEvent(void)</div><div class="ttdoc">Posts an empty event to the event queue.</div></div> | ||
132 | </div><!-- fragment --><p >Do not assume that callbacks will <em>only</em> be called in response to the above functions. While it is necessary to process events in one or more of the ways above, window systems that require GLFW to register callbacks of its own can pass events to GLFW in response to many window system function calls. GLFW will pass those events on to the application callbacks before returning.</p> | ||
133 | <p >For example, on Windows the system function that <a class="el" href="group__window.html#ga371911f12c74c504dd8d47d832d095cb">glfwSetWindowSize</a> is implemented with will send window size events directly to the event callback that every window has and that GLFW implements for its windows. If you have set a <a class="el" href="window_guide.html#window_size">window size callback</a> GLFW will call it in turn with the new size before everything returns back out of the <a class="el" href="group__window.html#ga371911f12c74c504dd8d47d832d095cb">glfwSetWindowSize</a> call.</p> | ||
134 | <h1><a class="anchor" id="input_keyboard"></a> | ||
135 | Keyboard input</h1> | ||
136 | <p >GLFW divides keyboard input into two categories; key events and character events. Key events relate to actual physical keyboard keys, whereas character events relate to the Unicode code points generated by pressing some of them.</p> | ||
137 | <p >Keys and characters do not map 1:1. A single key press may produce several characters, and a single character may require several keys to produce. This may not be the case on your machine, but your users are likely not all using the same keyboard layout, input method or even operating system as you.</p> | ||
138 | <h2><a class="anchor" id="input_key"></a> | ||
139 | Key input</h2> | ||
140 | <p >If you wish to be notified when a physical key is pressed or released or when it repeats, set a key callback.</p> | ||
141 | <div class="fragment"><div class="line"><a class="code hl_function" href="group__input.html#ga1caf18159767e761185e49a3be019f8d">glfwSetKeyCallback</a>(window, key_callback);</div> | ||
142 | <div class="ttc" id="agroup__input_html_ga1caf18159767e761185e49a3be019f8d"><div class="ttname"><a href="group__input.html#ga1caf18159767e761185e49a3be019f8d">glfwSetKeyCallback</a></div><div class="ttdeci">GLFWkeyfun glfwSetKeyCallback(GLFWwindow *window, GLFWkeyfun callback)</div><div class="ttdoc">Sets the key callback.</div></div> | ||
143 | </div><!-- fragment --><p >The callback function receives the <a class="el" href="group__keys.html">keyboard key</a>, platform-specific scancode, key action and <a class="el" href="group__mods.html">modifier bits</a>.</p> | ||
144 | <div class="fragment"><div class="line"><span class="keywordtype">void</span> key_callback(<a class="code hl_typedef" href="group__window.html#ga3c96d80d363e67d13a41b5d1821f3242">GLFWwindow</a>* window, <span class="keywordtype">int</span> key, <span class="keywordtype">int</span> scancode, <span class="keywordtype">int</span> action, <span class="keywordtype">int</span> mods)</div> | ||
145 | <div class="line">{</div> | ||
146 | <div class="line"> <span class="keywordflow">if</span> (key == <a class="code hl_define" href="group__keys.html#gabf48fcc3afbe69349df432b470c96ef2">GLFW_KEY_E</a> && action == <a class="code hl_define" href="group__input.html#ga2485743d0b59df3791c45951c4195265">GLFW_PRESS</a>)</div> | ||
147 | <div class="line"> activate_airship();</div> | ||
148 | <div class="line">}</div> | ||
149 | <div class="ttc" id="agroup__input_html_ga2485743d0b59df3791c45951c4195265"><div class="ttname"><a href="group__input.html#ga2485743d0b59df3791c45951c4195265">GLFW_PRESS</a></div><div class="ttdeci">#define GLFW_PRESS</div><div class="ttdoc">The key or mouse button was pressed.</div><div class="ttdef"><b>Definition:</b> glfw3.h:339</div></div> | ||
150 | <div class="ttc" id="agroup__keys_html_gabf48fcc3afbe69349df432b470c96ef2"><div class="ttname"><a href="group__keys.html#gabf48fcc3afbe69349df432b470c96ef2">GLFW_KEY_E</a></div><div class="ttdeci">#define GLFW_KEY_E</div><div class="ttdef"><b>Definition:</b> glfw3.h:417</div></div> | ||
151 | <div class="ttc" id="agroup__window_html_ga3c96d80d363e67d13a41b5d1821f3242"><div class="ttname"><a href="group__window.html#ga3c96d80d363e67d13a41b5d1821f3242">GLFWwindow</a></div><div class="ttdeci">struct GLFWwindow GLFWwindow</div><div class="ttdoc">Opaque window object.</div><div class="ttdef"><b>Definition:</b> glfw3.h:1186</div></div> | ||
152 | </div><!-- fragment --><p >The action is one of <code>GLFW_PRESS</code>, <code>GLFW_REPEAT</code> or <code>GLFW_RELEASE</code>. The key will be <code>GLFW_KEY_UNKNOWN</code> if GLFW lacks a key token for it, for example <em>E-mail</em> and <em>Play</em> keys.</p> | ||
153 | <p >The scancode is unique for every key, regardless of whether it has a key token. Scancodes are platform-specific but consistent over time, so keys will have different scancodes depending on the platform but they are safe to save to disk. You can query the scancode for any <a class="el" href="group__keys.html">named key</a> on the current platform with <a class="el" href="group__input.html#ga67ddd1b7dcbbaff03e4a76c0ea67103a">glfwGetKeyScancode</a>.</p> | ||
154 | <div class="fragment"><div class="line"><span class="keyword">const</span> <span class="keywordtype">int</span> scancode = <a class="code hl_function" href="group__input.html#ga67ddd1b7dcbbaff03e4a76c0ea67103a">glfwGetKeyScancode</a>(<a class="code hl_define" href="group__keys.html#gac1c42c0bf4192cea713c55598b06b744">GLFW_KEY_X</a>);</div> | ||
155 | <div class="line">set_key_mapping(scancode, swap_weapons);</div> | ||
156 | <div class="ttc" id="agroup__input_html_ga67ddd1b7dcbbaff03e4a76c0ea67103a"><div class="ttname"><a href="group__input.html#ga67ddd1b7dcbbaff03e4a76c0ea67103a">glfwGetKeyScancode</a></div><div class="ttdeci">int glfwGetKeyScancode(int key)</div><div class="ttdoc">Returns the platform-specific scancode of the specified key.</div></div> | ||
157 | <div class="ttc" id="agroup__keys_html_gac1c42c0bf4192cea713c55598b06b744"><div class="ttname"><a href="group__keys.html#gac1c42c0bf4192cea713c55598b06b744">GLFW_KEY_X</a></div><div class="ttdeci">#define GLFW_KEY_X</div><div class="ttdef"><b>Definition:</b> glfw3.h:436</div></div> | ||
158 | </div><!-- fragment --><p >The last reported state for every <a class="el" href="group__keys.html">named key</a> is also saved in per-window state arrays that can be polled with <a class="el" href="group__input.html#gadd341da06bc8d418b4dc3a3518af9ad2">glfwGetKey</a>.</p> | ||
159 | <div class="fragment"><div class="line"><span class="keywordtype">int</span> state = <a class="code hl_function" href="group__input.html#gadd341da06bc8d418b4dc3a3518af9ad2">glfwGetKey</a>(window, <a class="code hl_define" href="group__keys.html#gabf48fcc3afbe69349df432b470c96ef2">GLFW_KEY_E</a>);</div> | ||
160 | <div class="line"><span class="keywordflow">if</span> (state == <a class="code hl_define" href="group__input.html#ga2485743d0b59df3791c45951c4195265">GLFW_PRESS</a>)</div> | ||
161 | <div class="line">{</div> | ||
162 | <div class="line"> activate_airship();</div> | ||
163 | <div class="line">}</div> | ||
164 | <div class="ttc" id="agroup__input_html_gadd341da06bc8d418b4dc3a3518af9ad2"><div class="ttname"><a href="group__input.html#gadd341da06bc8d418b4dc3a3518af9ad2">glfwGetKey</a></div><div class="ttdeci">int glfwGetKey(GLFWwindow *window, int key)</div><div class="ttdoc">Returns the last reported state of a keyboard key for the specified window.</div></div> | ||
165 | </div><!-- fragment --><p >The returned state is one of <code>GLFW_PRESS</code> or <code>GLFW_RELEASE</code>.</p> | ||
166 | <p >This function only returns cached key event state. It does not poll the system for the current physical state of the key.</p> | ||
167 | <p ><a class="anchor" id="GLFW_STICKY_KEYS"></a>Whenever you poll state, you risk missing the state change you are looking for. If a pressed key is released again before you poll its state, you will have missed the key press. The recommended solution for this is to use a key callback, but there is also the <code>GLFW_STICKY_KEYS</code> input mode.</p> | ||
168 | <div class="fragment"><div class="line"><a class="code hl_function" href="group__input.html#gaa92336e173da9c8834558b54ee80563b">glfwSetInputMode</a>(window, <a class="code hl_define" href="glfw3_8h.html#ae3bbe2315b7691ab088159eb6c9110fc">GLFW_STICKY_KEYS</a>, <a class="code hl_define" href="group__init.html#ga2744fbb29b5631bb28802dbe0cf36eba">GLFW_TRUE</a>);</div> | ||
169 | <div class="ttc" id="aglfw3_8h_html_ae3bbe2315b7691ab088159eb6c9110fc"><div class="ttname"><a href="glfw3_8h.html#ae3bbe2315b7691ab088159eb6c9110fc">GLFW_STICKY_KEYS</a></div><div class="ttdeci">#define GLFW_STICKY_KEYS</div><div class="ttdef"><b>Definition:</b> glfw3.h:1050</div></div> | ||
170 | <div class="ttc" id="agroup__init_html_ga2744fbb29b5631bb28802dbe0cf36eba"><div class="ttname"><a href="group__init.html#ga2744fbb29b5631bb28802dbe0cf36eba">GLFW_TRUE</a></div><div class="ttdeci">#define GLFW_TRUE</div><div class="ttdoc">One.</div><div class="ttdef"><b>Definition:</b> glfw3.h:313</div></div> | ||
171 | <div class="ttc" id="agroup__input_html_gaa92336e173da9c8834558b54ee80563b"><div class="ttname"><a href="group__input.html#gaa92336e173da9c8834558b54ee80563b">glfwSetInputMode</a></div><div class="ttdeci">void glfwSetInputMode(GLFWwindow *window, int mode, int value)</div><div class="ttdoc">Sets an input option for the specified window.</div></div> | ||
172 | </div><!-- fragment --><p >When sticky keys mode is enabled, the pollable state of a key will remain <code>GLFW_PRESS</code> until the state of that key is polled with <a class="el" href="group__input.html#gadd341da06bc8d418b4dc3a3518af9ad2">glfwGetKey</a>. Once it has been polled, if a key release event had been processed in the meantime, the state will reset to <code>GLFW_RELEASE</code>, otherwise it will remain <code>GLFW_PRESS</code>.</p> | ||
173 | <p ><a class="anchor" id="GLFW_LOCK_KEY_MODS"></a>If you wish to know what the state of the Caps Lock and Num Lock keys was when input events were generated, set the <code>GLFW_LOCK_KEY_MODS</code> input mode.</p> | ||
174 | <div class="fragment"><div class="line"><a class="code hl_function" href="group__input.html#gaa92336e173da9c8834558b54ee80563b">glfwSetInputMode</a>(window, <a class="code hl_define" href="glfw3_8h.html#a07b84de0b52143e1958f88a7d9105947">GLFW_LOCK_KEY_MODS</a>, <a class="code hl_define" href="group__init.html#ga2744fbb29b5631bb28802dbe0cf36eba">GLFW_TRUE</a>);</div> | ||
175 | <div class="ttc" id="aglfw3_8h_html_a07b84de0b52143e1958f88a7d9105947"><div class="ttname"><a href="glfw3_8h.html#a07b84de0b52143e1958f88a7d9105947">GLFW_LOCK_KEY_MODS</a></div><div class="ttdeci">#define GLFW_LOCK_KEY_MODS</div><div class="ttdef"><b>Definition:</b> glfw3.h:1052</div></div> | ||
176 | </div><!-- fragment --><p >When this input mode is enabled, any callback that receives <a class="el" href="group__mods.html">modifier bits</a> will have the <a class="el" href="group__mods.html#gaefeef8fcf825a6e43e241b337897200f">GLFW_MOD_CAPS_LOCK</a> bit set if Caps Lock was on when the event occurred and the <a class="el" href="group__mods.html#ga64e020b8a42af8376e944baf61feecbe">GLFW_MOD_NUM_LOCK</a> bit set if Num Lock was on.</p> | ||
177 | <p >The <code>GLFW_KEY_LAST</code> constant holds the highest value of any <a class="el" href="group__keys.html">named key</a>.</p> | ||
178 | <h2><a class="anchor" id="input_char"></a> | ||
179 | Text input</h2> | ||
180 | <p >GLFW supports text input in the form of a stream of <a href="https://en.wikipedia.org/wiki/Unicode">Unicode code points</a>, as produced by the operating system text input system. Unlike key input, text input obeys keyboard layouts and modifier keys and supports composing characters using <a href="https://en.wikipedia.org/wiki/Dead_key">dead keys</a>. Once received, you can encode the code points into UTF-8 or any other encoding you prefer.</p> | ||
181 | <p >Because an <code>unsigned int</code> is 32 bits long on all platforms supported by GLFW, you can treat the code point argument as native endian UTF-32.</p> | ||
182 | <p >If you wish to offer regular text input, set a character callback.</p> | ||
183 | <div class="fragment"><div class="line"><a class="code hl_function" href="group__input.html#gab25c4a220fd8f5717718dbc487828996">glfwSetCharCallback</a>(window, character_callback);</div> | ||
184 | <div class="ttc" id="agroup__input_html_gab25c4a220fd8f5717718dbc487828996"><div class="ttname"><a href="group__input.html#gab25c4a220fd8f5717718dbc487828996">glfwSetCharCallback</a></div><div class="ttdeci">GLFWcharfun glfwSetCharCallback(GLFWwindow *window, GLFWcharfun callback)</div><div class="ttdoc">Sets the Unicode character callback.</div></div> | ||
185 | </div><!-- fragment --><p >The callback function receives Unicode code points for key events that would have led to regular text input and generally behaves as a standard text field on that platform.</p> | ||
186 | <div class="fragment"><div class="line"><span class="keywordtype">void</span> character_callback(<a class="code hl_typedef" href="group__window.html#ga3c96d80d363e67d13a41b5d1821f3242">GLFWwindow</a>* window, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> codepoint)</div> | ||
187 | <div class="line">{</div> | ||
188 | <div class="line">}</div> | ||
189 | </div><!-- fragment --><h2><a class="anchor" id="input_key_name"></a> | ||
190 | Key names</h2> | ||
191 | <p >If you wish to refer to keys by name, you can query the keyboard layout dependent name of printable keys with <a class="el" href="group__input.html#gaeaed62e69c3bd62b7ff8f7b19913ce4f">glfwGetKeyName</a>.</p> | ||
192 | <div class="fragment"><div class="line"><span class="keyword">const</span> <span class="keywordtype">char</span>* key_name = <a class="code hl_function" href="group__input.html#gaeaed62e69c3bd62b7ff8f7b19913ce4f">glfwGetKeyName</a>(<a class="code hl_define" href="group__keys.html#gaa06a712e6202661fc03da5bdb7b6e545">GLFW_KEY_W</a>, 0);</div> | ||
193 | <div class="line">show_tutorial_hint(<span class="stringliteral">"Press %s to move forward"</span>, key_name);</div> | ||
194 | <div class="ttc" id="agroup__input_html_gaeaed62e69c3bd62b7ff8f7b19913ce4f"><div class="ttname"><a href="group__input.html#gaeaed62e69c3bd62b7ff8f7b19913ce4f">glfwGetKeyName</a></div><div class="ttdeci">const char * glfwGetKeyName(int key, int scancode)</div><div class="ttdoc">Returns the layout-specific name of the specified printable key.</div></div> | ||
195 | <div class="ttc" id="agroup__keys_html_gaa06a712e6202661fc03da5bdb7b6e545"><div class="ttname"><a href="group__keys.html#gaa06a712e6202661fc03da5bdb7b6e545">GLFW_KEY_W</a></div><div class="ttdeci">#define GLFW_KEY_W</div><div class="ttdef"><b>Definition:</b> glfw3.h:435</div></div> | ||
196 | </div><!-- fragment --><p >This function can handle both <a class="el" href="input_guide.html#input_key">keys and scancodes</a>. If the specified key is <code>GLFW_KEY_UNKNOWN</code> then the scancode is used, otherwise it is ignored. This matches the behavior of the key callback, meaning the callback arguments can always be passed unmodified to this function.</p> | ||
197 | <h1><a class="anchor" id="input_mouse"></a> | ||
198 | Mouse input</h1> | ||
199 | <p >Mouse input comes in many forms, including mouse motion, button presses and scrolling offsets. The cursor appearance can also be changed, either to a custom image or a standard cursor shape from the system theme.</p> | ||
200 | <h2><a class="anchor" id="cursor_pos"></a> | ||
201 | Cursor position</h2> | ||
202 | <p >If you wish to be notified when the cursor moves over the window, set a cursor position callback.</p> | ||
203 | <div class="fragment"><div class="line"><a class="code hl_function" href="group__input.html#gac1f879ab7435d54d4d79bb469fe225d7">glfwSetCursorPosCallback</a>(window, cursor_position_callback);</div> | ||
204 | <div class="ttc" id="agroup__input_html_gac1f879ab7435d54d4d79bb469fe225d7"><div class="ttname"><a href="group__input.html#gac1f879ab7435d54d4d79bb469fe225d7">glfwSetCursorPosCallback</a></div><div class="ttdeci">GLFWcursorposfun glfwSetCursorPosCallback(GLFWwindow *window, GLFWcursorposfun callback)</div><div class="ttdoc">Sets the cursor position callback.</div></div> | ||
205 | </div><!-- fragment --><p >The callback functions receives the cursor position, measured in screen coordinates but relative to the top-left corner of the window content area. On platforms that provide it, the full sub-pixel cursor position is passed on.</p> | ||
206 | <div class="fragment"><div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span> cursor_position_callback(<a class="code hl_typedef" href="group__window.html#ga3c96d80d363e67d13a41b5d1821f3242">GLFWwindow</a>* window, <span class="keywordtype">double</span> xpos, <span class="keywordtype">double</span> ypos)</div> | ||
207 | <div class="line">{</div> | ||
208 | <div class="line">}</div> | ||
209 | </div><!-- fragment --><p >The cursor position is also saved per-window and can be polled with <a class="el" href="group__input.html#ga01d37b6c40133676b9cea60ca1d7c0cc">glfwGetCursorPos</a>.</p> | ||
210 | <div class="fragment"><div class="line"><span class="keywordtype">double</span> xpos, ypos;</div> | ||
211 | <div class="line"><a class="code hl_function" href="group__input.html#ga01d37b6c40133676b9cea60ca1d7c0cc">glfwGetCursorPos</a>(window, &xpos, &ypos);</div> | ||
212 | <div class="ttc" id="agroup__input_html_ga01d37b6c40133676b9cea60ca1d7c0cc"><div class="ttname"><a href="group__input.html#ga01d37b6c40133676b9cea60ca1d7c0cc">glfwGetCursorPos</a></div><div class="ttdeci">void glfwGetCursorPos(GLFWwindow *window, double *xpos, double *ypos)</div><div class="ttdoc">Retrieves the position of the cursor relative to the content area of the window.</div></div> | ||
213 | </div><!-- fragment --><h2><a class="anchor" id="cursor_mode"></a> | ||
214 | Cursor mode</h2> | ||
215 | <p ><a class="anchor" id="GLFW_CURSOR"></a>The <code>GLFW_CURSOR</code> input mode provides several cursor modes for special forms of mouse motion input. By default, the cursor mode is <code>GLFW_CURSOR_NORMAL</code>, meaning the regular arrow cursor (or another cursor set with <a class="el" href="group__input.html#gad3b4f38c8d5dae036bc8fa959e18343e">glfwSetCursor</a>) is used and cursor motion is not limited.</p> | ||
216 | <p >If you wish to implement mouse motion based camera controls or other input schemes that require unlimited mouse movement, set the cursor mode to <code>GLFW_CURSOR_DISABLED</code>.</p> | ||
217 | <div class="fragment"><div class="line"><a class="code hl_function" href="group__input.html#gaa92336e173da9c8834558b54ee80563b">glfwSetInputMode</a>(window, <a class="code hl_define" href="glfw3_8h.html#aade31da5b884a84a7625c6b059b9132c">GLFW_CURSOR</a>, <a class="code hl_define" href="glfw3_8h.html#a2315b99a329ce53e6a13a9d46fd5ca88">GLFW_CURSOR_DISABLED</a>);</div> | ||
218 | <div class="ttc" id="aglfw3_8h_html_a2315b99a329ce53e6a13a9d46fd5ca88"><div class="ttname"><a href="glfw3_8h.html#a2315b99a329ce53e6a13a9d46fd5ca88">GLFW_CURSOR_DISABLED</a></div><div class="ttdeci">#define GLFW_CURSOR_DISABLED</div><div class="ttdef"><b>Definition:</b> glfw3.h:1057</div></div> | ||
219 | <div class="ttc" id="aglfw3_8h_html_aade31da5b884a84a7625c6b059b9132c"><div class="ttname"><a href="glfw3_8h.html#aade31da5b884a84a7625c6b059b9132c">GLFW_CURSOR</a></div><div class="ttdeci">#define GLFW_CURSOR</div><div class="ttdef"><b>Definition:</b> glfw3.h:1049</div></div> | ||
220 | </div><!-- fragment --><p >This will hide the cursor and lock it to the specified window. GLFW will then take care of all the details of cursor re-centering and offset calculation and providing the application with a virtual cursor position. This virtual position is provided normally via both the cursor position callback and through polling.</p> | ||
221 | <dl class="section note"><dt>Note</dt><dd>You should not implement your own version of this functionality using other features of GLFW. It is not supported and will not work as robustly as <code>GLFW_CURSOR_DISABLED</code>.</dd></dl> | ||
222 | <p>If you only wish the cursor to become hidden when it is over a window but still want it to behave normally, set the cursor mode to <code>GLFW_CURSOR_HIDDEN</code>.</p> | ||
223 | <div class="fragment"><div class="line"><a class="code hl_function" href="group__input.html#gaa92336e173da9c8834558b54ee80563b">glfwSetInputMode</a>(window, <a class="code hl_define" href="glfw3_8h.html#aade31da5b884a84a7625c6b059b9132c">GLFW_CURSOR</a>, <a class="code hl_define" href="glfw3_8h.html#ac4d5cb9d78de8573349c58763d53bf11">GLFW_CURSOR_HIDDEN</a>);</div> | ||
224 | <div class="ttc" id="aglfw3_8h_html_ac4d5cb9d78de8573349c58763d53bf11"><div class="ttname"><a href="glfw3_8h.html#ac4d5cb9d78de8573349c58763d53bf11">GLFW_CURSOR_HIDDEN</a></div><div class="ttdeci">#define GLFW_CURSOR_HIDDEN</div><div class="ttdef"><b>Definition:</b> glfw3.h:1056</div></div> | ||
225 | </div><!-- fragment --><p >This mode puts no limit on the motion of the cursor.</p> | ||
226 | <p >To exit out of either of these special modes, restore the <code>GLFW_CURSOR_NORMAL</code> cursor mode.</p> | ||
227 | <div class="fragment"><div class="line"><a class="code hl_function" href="group__input.html#gaa92336e173da9c8834558b54ee80563b">glfwSetInputMode</a>(window, <a class="code hl_define" href="glfw3_8h.html#aade31da5b884a84a7625c6b059b9132c">GLFW_CURSOR</a>, <a class="code hl_define" href="glfw3_8h.html#ae04dd25c8577e19fa8c97368561f6c68">GLFW_CURSOR_NORMAL</a>);</div> | ||
228 | <div class="ttc" id="aglfw3_8h_html_ae04dd25c8577e19fa8c97368561f6c68"><div class="ttname"><a href="glfw3_8h.html#ae04dd25c8577e19fa8c97368561f6c68">GLFW_CURSOR_NORMAL</a></div><div class="ttdeci">#define GLFW_CURSOR_NORMAL</div><div class="ttdef"><b>Definition:</b> glfw3.h:1055</div></div> | ||
229 | </div><!-- fragment --><p ><a class="anchor" id="GLFW_RAW_MOUSE_MOTION"></a></p> | ||
230 | <h2><a class="anchor" id="raw_mouse_motion"></a> | ||
231 | Raw mouse motion</h2> | ||
232 | <p >When the cursor is disabled, raw (unscaled and unaccelerated) mouse motion can be enabled if available.</p> | ||
233 | <p >Raw mouse motion is closer to the actual motion of the mouse across a surface. It is not affected by the scaling and acceleration applied to the motion of the desktop cursor. That processing is suitable for a cursor while raw motion is better for controlling for example a 3D camera. Because of this, raw mouse motion is only provided when the cursor is disabled.</p> | ||
234 | <p >Call <a class="el" href="group__input.html#gae4ee0dbd0d256183e1ea4026d897e1c2">glfwRawMouseMotionSupported</a> to check if the current machine provides raw motion and set the <code>GLFW_RAW_MOUSE_MOTION</code> input mode to enable it. It is disabled by default.</p> | ||
235 | <div class="fragment"><div class="line"><span class="keywordflow">if</span> (<a class="code hl_function" href="group__input.html#gae4ee0dbd0d256183e1ea4026d897e1c2">glfwRawMouseMotionSupported</a>())</div> | ||
236 | <div class="line"> <a class="code hl_function" href="group__input.html#gaa92336e173da9c8834558b54ee80563b">glfwSetInputMode</a>(window, <a class="code hl_define" href="glfw3_8h.html#aeeda1be76a44a1fc97c1282e06281fbb">GLFW_RAW_MOUSE_MOTION</a>, <a class="code hl_define" href="group__init.html#ga2744fbb29b5631bb28802dbe0cf36eba">GLFW_TRUE</a>);</div> | ||
237 | <div class="ttc" id="aglfw3_8h_html_aeeda1be76a44a1fc97c1282e06281fbb"><div class="ttname"><a href="glfw3_8h.html#aeeda1be76a44a1fc97c1282e06281fbb">GLFW_RAW_MOUSE_MOTION</a></div><div class="ttdeci">#define GLFW_RAW_MOUSE_MOTION</div><div class="ttdef"><b>Definition:</b> glfw3.h:1053</div></div> | ||
238 | <div class="ttc" id="agroup__input_html_gae4ee0dbd0d256183e1ea4026d897e1c2"><div class="ttname"><a href="group__input.html#gae4ee0dbd0d256183e1ea4026d897e1c2">glfwRawMouseMotionSupported</a></div><div class="ttdeci">int glfwRawMouseMotionSupported(void)</div><div class="ttdoc">Returns whether raw mouse motion is supported.</div></div> | ||
239 | </div><!-- fragment --><p >If supported, raw mouse motion can be enabled or disabled per-window and at any time but it will only be provided when the cursor is disabled.</p> | ||
240 | <h2><a class="anchor" id="cursor_object"></a> | ||
241 | Cursor objects</h2> | ||
242 | <p >GLFW supports creating both custom and system theme cursor images, encapsulated as <a class="el" href="group__input.html#ga89261ae18c75e863aaf2656ecdd238f4">GLFWcursor</a> objects. They are created with <a class="el" href="group__input.html#ga556f604f73af156c0db0e97c081373c3">glfwCreateCursor</a> or <a class="el" href="group__input.html#gaf2fb2eb2c9dd842d1cef8a34e3c6403e">glfwCreateStandardCursor</a> and destroyed with <a class="el" href="group__input.html#ga81b952cd1764274d0db7fb3c5a79ba6a">glfwDestroyCursor</a>, or <a class="el" href="group__init.html#gaaae48c0a18607ea4a4ba951d939f0901">glfwTerminate</a>, if any remain.</p> | ||
243 | <h3><a class="anchor" id="cursor_custom"></a> | ||
244 | Custom cursor creation</h3> | ||
245 | <p >A custom cursor is created with <a class="el" href="group__input.html#ga556f604f73af156c0db0e97c081373c3">glfwCreateCursor</a>, which returns a handle to the created cursor object. For example, this creates a 16x16 white square cursor with the hot-spot in the upper-left corner:</p> | ||
246 | <div class="fragment"><div class="line"><span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> pixels[16 * 16 * 4];</div> | ||
247 | <div class="line">memset(pixels, 0xff, <span class="keyword">sizeof</span>(pixels));</div> | ||
248 | <div class="line"> </div> | ||
249 | <div class="line"><a class="code hl_struct" href="structGLFWimage.html">GLFWimage</a> image;</div> | ||
250 | <div class="line">image.<a class="code hl_variable" href="structGLFWimage.html#af6a71cc999fe6d3aea31dd7e9687d835">width</a> = 16;</div> | ||
251 | <div class="line">image.<a class="code hl_variable" href="structGLFWimage.html#a0b7d95368f0c80d5e5c9875057c7dbec">height</a> = 16;</div> | ||
252 | <div class="line">image.<a class="code hl_variable" href="structGLFWimage.html#a0c532a5c2bb715555279b7817daba0fb">pixels</a> = pixels;</div> | ||
253 | <div class="line"> </div> | ||
254 | <div class="line"><a class="code hl_typedef" href="group__input.html#ga89261ae18c75e863aaf2656ecdd238f4">GLFWcursor</a>* cursor = <a class="code hl_function" href="group__input.html#ga556f604f73af156c0db0e97c081373c3">glfwCreateCursor</a>(&image, 0, 0);</div> | ||
255 | <div class="ttc" id="agroup__input_html_ga556f604f73af156c0db0e97c081373c3"><div class="ttname"><a href="group__input.html#ga556f604f73af156c0db0e97c081373c3">glfwCreateCursor</a></div><div class="ttdeci">GLFWcursor * glfwCreateCursor(const GLFWimage *image, int xhot, int yhot)</div><div class="ttdoc">Creates a custom cursor.</div></div> | ||
256 | <div class="ttc" id="agroup__input_html_ga89261ae18c75e863aaf2656ecdd238f4"><div class="ttname"><a href="group__input.html#ga89261ae18c75e863aaf2656ecdd238f4">GLFWcursor</a></div><div class="ttdeci">struct GLFWcursor GLFWcursor</div><div class="ttdoc">Opaque cursor object.</div><div class="ttdef"><b>Definition:</b> glfw3.h:1198</div></div> | ||
257 | <div class="ttc" id="astructGLFWimage_html"><div class="ttname"><a href="structGLFWimage.html">GLFWimage</a></div><div class="ttdoc">Image data.</div><div class="ttdef"><b>Definition:</b> glfw3.h:1722</div></div> | ||
258 | <div class="ttc" id="astructGLFWimage_html_a0b7d95368f0c80d5e5c9875057c7dbec"><div class="ttname"><a href="structGLFWimage.html#a0b7d95368f0c80d5e5c9875057c7dbec">GLFWimage::height</a></div><div class="ttdeci">int height</div><div class="ttdef"><b>Definition:</b> glfw3.h:1728</div></div> | ||
259 | <div class="ttc" id="astructGLFWimage_html_a0c532a5c2bb715555279b7817daba0fb"><div class="ttname"><a href="structGLFWimage.html#a0c532a5c2bb715555279b7817daba0fb">GLFWimage::pixels</a></div><div class="ttdeci">unsigned char * pixels</div><div class="ttdef"><b>Definition:</b> glfw3.h:1731</div></div> | ||
260 | <div class="ttc" id="astructGLFWimage_html_af6a71cc999fe6d3aea31dd7e9687d835"><div class="ttname"><a href="structGLFWimage.html#af6a71cc999fe6d3aea31dd7e9687d835">GLFWimage::width</a></div><div class="ttdeci">int width</div><div class="ttdef"><b>Definition:</b> glfw3.h:1725</div></div> | ||
261 | </div><!-- fragment --><p >If cursor creation fails, <code>NULL</code> will be returned, so it is necessary to check the return value.</p> | ||
262 | <p >The image data is 32-bit, little-endian, non-premultiplied RGBA, i.e. eight bits per channel with the red channel first. The pixels are arranged canonically as sequential rows, starting from the top-left corner.</p> | ||
263 | <h3><a class="anchor" id="cursor_standard"></a> | ||
264 | Standard cursor creation</h3> | ||
265 | <p >A cursor with a <a class="el" href="group__shapes.html">standard shape</a> from the current system cursor theme can be can be created with <a class="el" href="group__input.html#gaf2fb2eb2c9dd842d1cef8a34e3c6403e">glfwCreateStandardCursor</a>.</p> | ||
266 | <div class="fragment"><div class="line"><a class="code hl_typedef" href="group__input.html#ga89261ae18c75e863aaf2656ecdd238f4">GLFWcursor</a>* cursor = <a class="code hl_function" href="group__input.html#gaf2fb2eb2c9dd842d1cef8a34e3c6403e">glfwCreateStandardCursor</a>(<a class="code hl_define" href="group__shapes.html#gabb3eb0109f11bb808fc34659177ca962">GLFW_HRESIZE_CURSOR</a>);</div> | ||
267 | <div class="ttc" id="agroup__input_html_gaf2fb2eb2c9dd842d1cef8a34e3c6403e"><div class="ttname"><a href="group__input.html#gaf2fb2eb2c9dd842d1cef8a34e3c6403e">glfwCreateStandardCursor</a></div><div class="ttdeci">GLFWcursor * glfwCreateStandardCursor(int shape)</div><div class="ttdoc">Creates a cursor with a standard shape.</div></div> | ||
268 | <div class="ttc" id="agroup__shapes_html_gabb3eb0109f11bb808fc34659177ca962"><div class="ttname"><a href="group__shapes.html#gabb3eb0109f11bb808fc34659177ca962">GLFW_HRESIZE_CURSOR</a></div><div class="ttdeci">#define GLFW_HRESIZE_CURSOR</div><div class="ttdoc">The horizontal resize arrow shape.</div><div class="ttdef"><b>Definition:</b> glfw3.h:1099</div></div> | ||
269 | </div><!-- fragment --><p >These cursor objects behave in the exact same way as those created with <a class="el" href="group__input.html#ga556f604f73af156c0db0e97c081373c3">glfwCreateCursor</a> except that the system cursor theme provides the actual image.</p> | ||
270 | <h3><a class="anchor" id="cursor_destruction"></a> | ||
271 | Cursor destruction</h3> | ||
272 | <p >When a cursor is no longer needed, destroy it with <a class="el" href="group__input.html#ga81b952cd1764274d0db7fb3c5a79ba6a">glfwDestroyCursor</a>.</p> | ||
273 | <div class="fragment"><div class="line"><a class="code hl_function" href="group__input.html#ga81b952cd1764274d0db7fb3c5a79ba6a">glfwDestroyCursor</a>(cursor);</div> | ||
274 | <div class="ttc" id="agroup__input_html_ga81b952cd1764274d0db7fb3c5a79ba6a"><div class="ttname"><a href="group__input.html#ga81b952cd1764274d0db7fb3c5a79ba6a">glfwDestroyCursor</a></div><div class="ttdeci">void glfwDestroyCursor(GLFWcursor *cursor)</div><div class="ttdoc">Destroys a cursor.</div></div> | ||
275 | </div><!-- fragment --><p >Cursor destruction always succeeds. If the cursor is current for any window, that window will revert to the default cursor. This does not affect the cursor mode. All remaining cursors are destroyed when <a class="el" href="group__init.html#gaaae48c0a18607ea4a4ba951d939f0901">glfwTerminate</a> is called.</p> | ||
276 | <h3><a class="anchor" id="cursor_set"></a> | ||
277 | Cursor setting</h3> | ||
278 | <p >A cursor can be set as current for a window with <a class="el" href="group__input.html#gad3b4f38c8d5dae036bc8fa959e18343e">glfwSetCursor</a>.</p> | ||
279 | <div class="fragment"><div class="line"><a class="code hl_function" href="group__input.html#gad3b4f38c8d5dae036bc8fa959e18343e">glfwSetCursor</a>(window, cursor);</div> | ||
280 | <div class="ttc" id="agroup__input_html_gad3b4f38c8d5dae036bc8fa959e18343e"><div class="ttname"><a href="group__input.html#gad3b4f38c8d5dae036bc8fa959e18343e">glfwSetCursor</a></div><div class="ttdeci">void glfwSetCursor(GLFWwindow *window, GLFWcursor *cursor)</div><div class="ttdoc">Sets the cursor for the window.</div></div> | ||
281 | </div><!-- fragment --><p >Once set, the cursor image will be used as long as the system cursor is over the content area of the window and the <a class="el" href="input_guide.html#cursor_mode">cursor mode</a> is set to <code>GLFW_CURSOR_NORMAL</code>.</p> | ||
282 | <p >A single cursor may be set for any number of windows.</p> | ||
283 | <p >To revert to the default cursor, set the cursor of that window to <code>NULL</code>.</p> | ||
284 | <div class="fragment"><div class="line"><a class="code hl_function" href="group__input.html#gad3b4f38c8d5dae036bc8fa959e18343e">glfwSetCursor</a>(window, NULL);</div> | ||
285 | </div><!-- fragment --><p >When a cursor is destroyed, any window that has it set will revert to the default cursor. This does not affect the cursor mode.</p> | ||
286 | <h2><a class="anchor" id="cursor_enter"></a> | ||
287 | Cursor enter/leave events</h2> | ||
288 | <p >If you wish to be notified when the cursor enters or leaves the content area of a window, set a cursor enter/leave callback.</p> | ||
289 | <div class="fragment"><div class="line"><a class="code hl_function" href="group__input.html#gad27f8ad0142c038a281466c0966817d8">glfwSetCursorEnterCallback</a>(window, cursor_enter_callback);</div> | ||
290 | <div class="ttc" id="agroup__input_html_gad27f8ad0142c038a281466c0966817d8"><div class="ttname"><a href="group__input.html#gad27f8ad0142c038a281466c0966817d8">glfwSetCursorEnterCallback</a></div><div class="ttdeci">GLFWcursorenterfun glfwSetCursorEnterCallback(GLFWwindow *window, GLFWcursorenterfun callback)</div><div class="ttdoc">Sets the cursor enter/leave callback.</div></div> | ||
291 | </div><!-- fragment --><p >The callback function receives the new classification of the cursor.</p> | ||
292 | <div class="fragment"><div class="line"><span class="keywordtype">void</span> cursor_enter_callback(<a class="code hl_typedef" href="group__window.html#ga3c96d80d363e67d13a41b5d1821f3242">GLFWwindow</a>* window, <span class="keywordtype">int</span> entered)</div> | ||
293 | <div class="line">{</div> | ||
294 | <div class="line"> <span class="keywordflow">if</span> (entered)</div> | ||
295 | <div class="line"> {</div> | ||
296 | <div class="line"> <span class="comment">// The cursor entered the content area of the window</span></div> | ||
297 | <div class="line"> }</div> | ||
298 | <div class="line"> <span class="keywordflow">else</span></div> | ||
299 | <div class="line"> {</div> | ||
300 | <div class="line"> <span class="comment">// The cursor left the content area of the window</span></div> | ||
301 | <div class="line"> }</div> | ||
302 | <div class="line">}</div> | ||
303 | </div><!-- fragment --><p >You can query whether the cursor is currently inside the content area of the window with the <a class="el" href="window_guide.html#GLFW_HOVERED_attrib">GLFW_HOVERED</a> window attribute.</p> | ||
304 | <div class="fragment"><div class="line"><span class="keywordflow">if</span> (<a class="code hl_function" href="group__window.html#gacccb29947ea4b16860ebef42c2cb9337">glfwGetWindowAttrib</a>(window, <a class="code hl_define" href="group__window.html#ga8665c71c6fa3d22425c6a0e8a3f89d8a">GLFW_HOVERED</a>))</div> | ||
305 | <div class="line">{</div> | ||
306 | <div class="line"> highlight_interface();</div> | ||
307 | <div class="line">}</div> | ||
308 | <div class="ttc" id="agroup__window_html_ga8665c71c6fa3d22425c6a0e8a3f89d8a"><div class="ttname"><a href="group__window.html#ga8665c71c6fa3d22425c6a0e8a3f89d8a">GLFW_HOVERED</a></div><div class="ttdeci">#define GLFW_HOVERED</div><div class="ttdoc">Mouse cursor hover window attribute.</div><div class="ttdef"><b>Definition:</b> glfw3.h:856</div></div> | ||
309 | <div class="ttc" id="agroup__window_html_gacccb29947ea4b16860ebef42c2cb9337"><div class="ttname"><a href="group__window.html#gacccb29947ea4b16860ebef42c2cb9337">glfwGetWindowAttrib</a></div><div class="ttdeci">int glfwGetWindowAttrib(GLFWwindow *window, int attrib)</div><div class="ttdoc">Returns an attribute of the specified window.</div></div> | ||
310 | </div><!-- fragment --><h2><a class="anchor" id="input_mouse_button"></a> | ||
311 | Mouse button input</h2> | ||
312 | <p >If you wish to be notified when a mouse button is pressed or released, set a mouse button callback.</p> | ||
313 | <div class="fragment"><div class="line"><a class="code hl_function" href="group__input.html#ga6ab84420974d812bee700e45284a723c">glfwSetMouseButtonCallback</a>(window, mouse_button_callback);</div> | ||
314 | <div class="ttc" id="agroup__input_html_ga6ab84420974d812bee700e45284a723c"><div class="ttname"><a href="group__input.html#ga6ab84420974d812bee700e45284a723c">glfwSetMouseButtonCallback</a></div><div class="ttdeci">GLFWmousebuttonfun glfwSetMouseButtonCallback(GLFWwindow *window, GLFWmousebuttonfun callback)</div><div class="ttdoc">Sets the mouse button callback.</div></div> | ||
315 | </div><!-- fragment --><p >The callback function receives the <a class="el" href="group__buttons.html">mouse button</a>, button action and <a class="el" href="group__mods.html">modifier bits</a>.</p> | ||
316 | <div class="fragment"><div class="line"><span class="keywordtype">void</span> mouse_button_callback(<a class="code hl_typedef" href="group__window.html#ga3c96d80d363e67d13a41b5d1821f3242">GLFWwindow</a>* window, <span class="keywordtype">int</span> button, <span class="keywordtype">int</span> action, <span class="keywordtype">int</span> mods)</div> | ||
317 | <div class="line">{</div> | ||
318 | <div class="line"> <span class="keywordflow">if</span> (button == <a class="code hl_define" href="group__buttons.html#ga3e2f2cf3c4942df73cc094247d275e74">GLFW_MOUSE_BUTTON_RIGHT</a> && action == <a class="code hl_define" href="group__input.html#ga2485743d0b59df3791c45951c4195265">GLFW_PRESS</a>)</div> | ||
319 | <div class="line"> popup_menu();</div> | ||
320 | <div class="line">}</div> | ||
321 | <div class="ttc" id="agroup__buttons_html_ga3e2f2cf3c4942df73cc094247d275e74"><div class="ttname"><a href="group__buttons.html#ga3e2f2cf3c4942df73cc094247d275e74">GLFW_MOUSE_BUTTON_RIGHT</a></div><div class="ttdeci">#define GLFW_MOUSE_BUTTON_RIGHT</div><div class="ttdef"><b>Definition:</b> glfw3.h:582</div></div> | ||
322 | </div><!-- fragment --><p >The action is one of <code>GLFW_PRESS</code> or <code>GLFW_RELEASE</code>.</p> | ||
323 | <p >Mouse button states for <a class="el" href="group__buttons.html">named buttons</a> are also saved in per-window state arrays that can be polled with <a class="el" href="group__input.html#gac1473feacb5996c01a7a5a33b5066704">glfwGetMouseButton</a>.</p> | ||
324 | <div class="fragment"><div class="line"><span class="keywordtype">int</span> state = <a class="code hl_function" href="group__input.html#gac1473feacb5996c01a7a5a33b5066704">glfwGetMouseButton</a>(window, <a class="code hl_define" href="group__buttons.html#gaf37100431dcd5082d48f95ee8bc8cd56">GLFW_MOUSE_BUTTON_LEFT</a>);</div> | ||
325 | <div class="line"><span class="keywordflow">if</span> (state == <a class="code hl_define" href="group__input.html#ga2485743d0b59df3791c45951c4195265">GLFW_PRESS</a>)</div> | ||
326 | <div class="line">{</div> | ||
327 | <div class="line"> upgrade_cow();</div> | ||
328 | <div class="line">}</div> | ||
329 | <div class="ttc" id="agroup__buttons_html_gaf37100431dcd5082d48f95ee8bc8cd56"><div class="ttname"><a href="group__buttons.html#gaf37100431dcd5082d48f95ee8bc8cd56">GLFW_MOUSE_BUTTON_LEFT</a></div><div class="ttdeci">#define GLFW_MOUSE_BUTTON_LEFT</div><div class="ttdef"><b>Definition:</b> glfw3.h:581</div></div> | ||
330 | <div class="ttc" id="agroup__input_html_gac1473feacb5996c01a7a5a33b5066704"><div class="ttname"><a href="group__input.html#gac1473feacb5996c01a7a5a33b5066704">glfwGetMouseButton</a></div><div class="ttdeci">int glfwGetMouseButton(GLFWwindow *window, int button)</div><div class="ttdoc">Returns the last reported state of a mouse button for the specified window.</div></div> | ||
331 | </div><!-- fragment --><p >The returned state is one of <code>GLFW_PRESS</code> or <code>GLFW_RELEASE</code>.</p> | ||
332 | <p >This function only returns cached mouse button event state. It does not poll the system for the current state of the mouse button.</p> | ||
333 | <p ><a class="anchor" id="GLFW_STICKY_MOUSE_BUTTONS"></a>Whenever you poll state, you risk missing the state change you are looking for. If a pressed mouse button is released again before you poll its state, you will have missed the button press. The recommended solution for this is to use a mouse button callback, but there is also the <code>GLFW_STICKY_MOUSE_BUTTONS</code> input mode.</p> | ||
334 | <div class="fragment"><div class="line"><a class="code hl_function" href="group__input.html#gaa92336e173da9c8834558b54ee80563b">glfwSetInputMode</a>(window, <a class="code hl_define" href="glfw3_8h.html#a4d7ce8ce71030c3b04e2b78145bc59d1">GLFW_STICKY_MOUSE_BUTTONS</a>, <a class="code hl_define" href="group__init.html#ga2744fbb29b5631bb28802dbe0cf36eba">GLFW_TRUE</a>);</div> | ||
335 | <div class="ttc" id="aglfw3_8h_html_a4d7ce8ce71030c3b04e2b78145bc59d1"><div class="ttname"><a href="glfw3_8h.html#a4d7ce8ce71030c3b04e2b78145bc59d1">GLFW_STICKY_MOUSE_BUTTONS</a></div><div class="ttdeci">#define GLFW_STICKY_MOUSE_BUTTONS</div><div class="ttdef"><b>Definition:</b> glfw3.h:1051</div></div> | ||
336 | </div><!-- fragment --><p >When sticky mouse buttons mode is enabled, the pollable state of a mouse button will remain <code>GLFW_PRESS</code> until the state of that button is polled with <a class="el" href="group__input.html#gac1473feacb5996c01a7a5a33b5066704">glfwGetMouseButton</a>. Once it has been polled, if a mouse button release event had been processed in the meantime, the state will reset to <code>GLFW_RELEASE</code>, otherwise it will remain <code>GLFW_PRESS</code>.</p> | ||
337 | <p >The <code>GLFW_MOUSE_BUTTON_LAST</code> constant holds the highest value of any <a class="el" href="group__buttons.html">named button</a>.</p> | ||
338 | <h2><a class="anchor" id="scrolling"></a> | ||
339 | Scroll input</h2> | ||
340 | <p >If you wish to be notified when the user scrolls, whether with a mouse wheel or touchpad gesture, set a scroll callback.</p> | ||
341 | <div class="fragment"><div class="line"><a class="code hl_function" href="group__input.html#ga571e45a030ae4061f746ed56cb76aede">glfwSetScrollCallback</a>(window, scroll_callback);</div> | ||
342 | <div class="ttc" id="agroup__input_html_ga571e45a030ae4061f746ed56cb76aede"><div class="ttname"><a href="group__input.html#ga571e45a030ae4061f746ed56cb76aede">glfwSetScrollCallback</a></div><div class="ttdeci">GLFWscrollfun glfwSetScrollCallback(GLFWwindow *window, GLFWscrollfun callback)</div><div class="ttdoc">Sets the scroll callback.</div></div> | ||
343 | </div><!-- fragment --><p >The callback function receives two-dimensional scroll offsets.</p> | ||
344 | <div class="fragment"><div class="line"><span class="keywordtype">void</span> scroll_callback(<a class="code hl_typedef" href="group__window.html#ga3c96d80d363e67d13a41b5d1821f3242">GLFWwindow</a>* window, <span class="keywordtype">double</span> xoffset, <span class="keywordtype">double</span> yoffset)</div> | ||
345 | <div class="line">{</div> | ||
346 | <div class="line">}</div> | ||
347 | </div><!-- fragment --><p >A normal mouse wheel, being vertical, provides offsets along the Y-axis.</p> | ||
348 | <h1><a class="anchor" id="joystick"></a> | ||
349 | Joystick input</h1> | ||
350 | <p >The joystick functions expose connected joysticks and controllers, with both referred to as joysticks. It supports up to sixteen joysticks, ranging from <code>GLFW_JOYSTICK_1</code>, <code>GLFW_JOYSTICK_2</code> up to and including <code>GLFW_JOYSTICK_16</code> or <code>GLFW_JOYSTICK_LAST</code>. You can test whether a <a class="el" href="group__joysticks.html">joystick</a> is present with <a class="el" href="group__input.html#gaed0966cee139d815317f9ffcba64c9f1">glfwJoystickPresent</a>.</p> | ||
351 | <div class="fragment"><div class="line"><span class="keywordtype">int</span> present = <a class="code hl_function" href="group__input.html#gaed0966cee139d815317f9ffcba64c9f1">glfwJoystickPresent</a>(<a class="code hl_define" href="group__joysticks.html#ga34a0443d059e9f22272cd4669073f73d">GLFW_JOYSTICK_1</a>);</div> | ||
352 | <div class="ttc" id="agroup__input_html_gaed0966cee139d815317f9ffcba64c9f1"><div class="ttname"><a href="group__input.html#gaed0966cee139d815317f9ffcba64c9f1">glfwJoystickPresent</a></div><div class="ttdeci">int glfwJoystickPresent(int jid)</div><div class="ttdoc">Returns whether the specified joystick is present.</div></div> | ||
353 | <div class="ttc" id="agroup__joysticks_html_ga34a0443d059e9f22272cd4669073f73d"><div class="ttname"><a href="group__joysticks.html#ga34a0443d059e9f22272cd4669073f73d">GLFW_JOYSTICK_1</a></div><div class="ttdeci">#define GLFW_JOYSTICK_1</div><div class="ttdef"><b>Definition:</b> glfw3.h:593</div></div> | ||
354 | </div><!-- fragment --><p >Each joystick has zero or more axes, zero or more buttons, zero or more hats, a human-readable name, a user pointer and an SDL compatible GUID.</p> | ||
355 | <p >When GLFW is initialized, detected joysticks are added to the beginning of the array. Once a joystick is detected, it keeps its assigned ID until it is disconnected or the library is terminated, so as joysticks are connected and disconnected, there may appear gaps in the IDs.</p> | ||
356 | <p >Joystick axis, button and hat state is updated when polled and does not require a window to be created or events to be processed. However, if you want joystick connection and disconnection events reliably delivered to the <a class="el" href="input_guide.html#joystick_event">joystick callback</a> then you must <a class="el" href="input_guide.html#events">process events</a>.</p> | ||
357 | <p >To see all the properties of all connected joysticks in real-time, run the <code>joysticks</code> test program.</p> | ||
358 | <h2><a class="anchor" id="joystick_axis"></a> | ||
359 | Joystick axis states</h2> | ||
360 | <p >The positions of all axes of a joystick are returned by <a class="el" href="group__input.html#gaeb1c0191d3140a233a682987c61eb408">glfwGetJoystickAxes</a>. See the reference documentation for the lifetime of the returned array.</p> | ||
361 | <div class="fragment"><div class="line"><span class="keywordtype">int</span> count;</div> | ||
362 | <div class="line"><span class="keyword">const</span> <span class="keywordtype">float</span>* axes = <a class="code hl_function" href="group__input.html#gaeb1c0191d3140a233a682987c61eb408">glfwGetJoystickAxes</a>(<a class="code hl_define" href="group__joysticks.html#gae43281bc66d3fa5089fb50c3e7a28695">GLFW_JOYSTICK_5</a>, &count);</div> | ||
363 | <div class="ttc" id="agroup__input_html_gaeb1c0191d3140a233a682987c61eb408"><div class="ttname"><a href="group__input.html#gaeb1c0191d3140a233a682987c61eb408">glfwGetJoystickAxes</a></div><div class="ttdeci">const float * glfwGetJoystickAxes(int jid, int *count)</div><div class="ttdoc">Returns the values of all axes of the specified joystick.</div></div> | ||
364 | <div class="ttc" id="agroup__joysticks_html_gae43281bc66d3fa5089fb50c3e7a28695"><div class="ttname"><a href="group__joysticks.html#gae43281bc66d3fa5089fb50c3e7a28695">GLFW_JOYSTICK_5</a></div><div class="ttdeci">#define GLFW_JOYSTICK_5</div><div class="ttdef"><b>Definition:</b> glfw3.h:597</div></div> | ||
365 | </div><!-- fragment --><p >Each element in the returned array is a value between -1.0 and 1.0.</p> | ||
366 | <h2><a class="anchor" id="joystick_button"></a> | ||
367 | Joystick button states</h2> | ||
368 | <p >The states of all buttons of a joystick are returned by <a class="el" href="group__input.html#ga5ffe34739d3dc97efe432ed2d81d9938">glfwGetJoystickButtons</a>. See the reference documentation for the lifetime of the returned array.</p> | ||
369 | <div class="fragment"><div class="line"><span class="keywordtype">int</span> count;</div> | ||
370 | <div class="line"><span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>* buttons = <a class="code hl_function" href="group__input.html#ga5ffe34739d3dc97efe432ed2d81d9938">glfwGetJoystickButtons</a>(<a class="code hl_define" href="group__joysticks.html#gae6f3eedfeb42424c2f5e3161efb0b654">GLFW_JOYSTICK_3</a>, &count);</div> | ||
371 | <div class="ttc" id="agroup__input_html_ga5ffe34739d3dc97efe432ed2d81d9938"><div class="ttname"><a href="group__input.html#ga5ffe34739d3dc97efe432ed2d81d9938">glfwGetJoystickButtons</a></div><div class="ttdeci">const unsigned char * glfwGetJoystickButtons(int jid, int *count)</div><div class="ttdoc">Returns the state of all buttons of the specified joystick.</div></div> | ||
372 | <div class="ttc" id="agroup__joysticks_html_gae6f3eedfeb42424c2f5e3161efb0b654"><div class="ttname"><a href="group__joysticks.html#gae6f3eedfeb42424c2f5e3161efb0b654">GLFW_JOYSTICK_3</a></div><div class="ttdeci">#define GLFW_JOYSTICK_3</div><div class="ttdef"><b>Definition:</b> glfw3.h:595</div></div> | ||
373 | </div><!-- fragment --><p >Each element in the returned array is either <code>GLFW_PRESS</code> or <code>GLFW_RELEASE</code>.</p> | ||
374 | <p >For backward compatibility with earlier versions that did not have <a class="el" href="group__input.html#ga06e660841b3e79c54da4f54a932c5a2c">glfwGetJoystickHats</a>, the button array by default also includes all hats. See the reference documentation for <a class="el" href="group__input.html#ga5ffe34739d3dc97efe432ed2d81d9938">glfwGetJoystickButtons</a> for details.</p> | ||
375 | <h2><a class="anchor" id="joystick_hat"></a> | ||
376 | Joystick hat states</h2> | ||
377 | <p >The states of all hats are returned by <a class="el" href="group__input.html#ga06e660841b3e79c54da4f54a932c5a2c">glfwGetJoystickHats</a>. See the reference documentation for the lifetime of the returned array.</p> | ||
378 | <div class="fragment"><div class="line"><span class="keywordtype">int</span> count;</div> | ||
379 | <div class="line"><span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>* hats = <a class="code hl_function" href="group__input.html#ga06e660841b3e79c54da4f54a932c5a2c">glfwGetJoystickHats</a>(<a class="code hl_define" href="group__joysticks.html#ga20a9f4f3aaefed9ea5e66072fc588b87">GLFW_JOYSTICK_7</a>, &count);</div> | ||
380 | <div class="ttc" id="agroup__input_html_ga06e660841b3e79c54da4f54a932c5a2c"><div class="ttname"><a href="group__input.html#ga06e660841b3e79c54da4f54a932c5a2c">glfwGetJoystickHats</a></div><div class="ttdeci">const unsigned char * glfwGetJoystickHats(int jid, int *count)</div><div class="ttdoc">Returns the state of all hats of the specified joystick.</div></div> | ||
381 | <div class="ttc" id="agroup__joysticks_html_ga20a9f4f3aaefed9ea5e66072fc588b87"><div class="ttname"><a href="group__joysticks.html#ga20a9f4f3aaefed9ea5e66072fc588b87">GLFW_JOYSTICK_7</a></div><div class="ttdeci">#define GLFW_JOYSTICK_7</div><div class="ttdef"><b>Definition:</b> glfw3.h:599</div></div> | ||
382 | </div><!-- fragment --><p >Each element in the returned array is one of the following:</p> | ||
383 | <table class="markdownTable"> | ||
384 | <tr class="markdownTableHead"> | ||
385 | <th class="markdownTableHeadNone">Name </th><th class="markdownTableHeadNone">Value </th></tr> | ||
386 | <tr class="markdownTableRowOdd"> | ||
387 | <td class="markdownTableBodyNone"><code>GLFW_HAT_CENTERED</code> </td><td class="markdownTableBodyNone">0 </td></tr> | ||
388 | <tr class="markdownTableRowEven"> | ||
389 | <td class="markdownTableBodyNone"><code>GLFW_HAT_UP</code> </td><td class="markdownTableBodyNone">1 </td></tr> | ||
390 | <tr class="markdownTableRowOdd"> | ||
391 | <td class="markdownTableBodyNone"><code>GLFW_HAT_RIGHT</code> </td><td class="markdownTableBodyNone">2 </td></tr> | ||
392 | <tr class="markdownTableRowEven"> | ||
393 | <td class="markdownTableBodyNone"><code>GLFW_HAT_DOWN</code> </td><td class="markdownTableBodyNone">4 </td></tr> | ||
394 | <tr class="markdownTableRowOdd"> | ||
395 | <td class="markdownTableBodyNone"><code>GLFW_HAT_LEFT</code> </td><td class="markdownTableBodyNone">8 </td></tr> | ||
396 | <tr class="markdownTableRowEven"> | ||
397 | <td class="markdownTableBodyNone"><code>GLFW_HAT_RIGHT_UP</code> </td><td class="markdownTableBodyNone"><code>GLFW_HAT_RIGHT</code> | <code>GLFW_HAT_UP</code> </td></tr> | ||
398 | <tr class="markdownTableRowOdd"> | ||
399 | <td class="markdownTableBodyNone"><code>GLFW_HAT_RIGHT_DOWN</code> </td><td class="markdownTableBodyNone"><code>GLFW_HAT_RIGHT</code> | <code>GLFW_HAT_DOWN</code> </td></tr> | ||
400 | <tr class="markdownTableRowEven"> | ||
401 | <td class="markdownTableBodyNone"><code>GLFW_HAT_LEFT_UP</code> </td><td class="markdownTableBodyNone"><code>GLFW_HAT_LEFT</code> | <code>GLFW_HAT_UP</code> </td></tr> | ||
402 | <tr class="markdownTableRowOdd"> | ||
403 | <td class="markdownTableBodyNone"><code>GLFW_HAT_LEFT_DOWN</code> </td><td class="markdownTableBodyNone"><code>GLFW_HAT_LEFT</code> | <code>GLFW_HAT_DOWN</code> </td></tr> | ||
404 | </table> | ||
405 | <p >The diagonal directions are bitwise combinations of the primary (up, right, down and left) directions and you can test for these individually by ANDing it with the corresponding direction.</p> | ||
406 | <div class="fragment"><div class="line"><span class="keywordflow">if</span> (hats[2] & <a class="code hl_define" href="group__hat__state.html#ga252586e3bbde75f4b0e07ad3124867f5">GLFW_HAT_RIGHT</a>)</div> | ||
407 | <div class="line">{</div> | ||
408 | <div class="line"> <span class="comment">// State of hat 2 could be right-up, right or right-down</span></div> | ||
409 | <div class="line">}</div> | ||
410 | <div class="ttc" id="agroup__hat__state_html_ga252586e3bbde75f4b0e07ad3124867f5"><div class="ttname"><a href="group__hat__state.html#ga252586e3bbde75f4b0e07ad3124867f5">GLFW_HAT_RIGHT</a></div><div class="ttdeci">#define GLFW_HAT_RIGHT</div><div class="ttdef"><b>Definition:</b> glfw3.h:358</div></div> | ||
411 | </div><!-- fragment --><p >For backward compatibility with earlier versions that did not have <a class="el" href="group__input.html#ga06e660841b3e79c54da4f54a932c5a2c">glfwGetJoystickHats</a>, all hats are by default also included in the button array. See the reference documentation for <a class="el" href="group__input.html#ga5ffe34739d3dc97efe432ed2d81d9938">glfwGetJoystickButtons</a> for details.</p> | ||
412 | <h2><a class="anchor" id="joystick_name"></a> | ||
413 | Joystick name</h2> | ||
414 | <p >The human-readable, UTF-8 encoded name of a joystick is returned by <a class="el" href="group__input.html#gac6a8e769e18e0bcfa9097793fc2c3978">glfwGetJoystickName</a>. See the reference documentation for the lifetime of the returned string.</p> | ||
415 | <div class="fragment"><div class="line"><span class="keyword">const</span> <span class="keywordtype">char</span>* name = <a class="code hl_function" href="group__input.html#gac6a8e769e18e0bcfa9097793fc2c3978">glfwGetJoystickName</a>(<a class="code hl_define" href="group__joysticks.html#ga97ddbcad02b7f48d74fad4ddb08fff59">GLFW_JOYSTICK_4</a>);</div> | ||
416 | <div class="ttc" id="agroup__input_html_gac6a8e769e18e0bcfa9097793fc2c3978"><div class="ttname"><a href="group__input.html#gac6a8e769e18e0bcfa9097793fc2c3978">glfwGetJoystickName</a></div><div class="ttdeci">const char * glfwGetJoystickName(int jid)</div><div class="ttdoc">Returns the name of the specified joystick.</div></div> | ||
417 | <div class="ttc" id="agroup__joysticks_html_ga97ddbcad02b7f48d74fad4ddb08fff59"><div class="ttname"><a href="group__joysticks.html#ga97ddbcad02b7f48d74fad4ddb08fff59">GLFW_JOYSTICK_4</a></div><div class="ttdeci">#define GLFW_JOYSTICK_4</div><div class="ttdef"><b>Definition:</b> glfw3.h:596</div></div> | ||
418 | </div><!-- fragment --><p >Joystick names are not guaranteed to be unique. Two joysticks of the same model and make may have the same name. Only the <a class="el" href="group__joysticks.html">joystick ID</a> is guaranteed to be unique, and only until that joystick is disconnected.</p> | ||
419 | <h2><a class="anchor" id="joystick_userptr"></a> | ||
420 | Joystick user pointer</h2> | ||
421 | <p >Each joystick has a user pointer that can be set with <a class="el" href="group__input.html#ga6b2f72d64d636b48a727b437cbb7489e">glfwSetJoystickUserPointer</a> and queried with <a class="el" href="group__input.html#ga18cefd7265d1fa04f3fd38a6746db5f3">glfwGetJoystickUserPointer</a>. This can be used for any purpose you need and will not be modified by GLFW. The value will be kept until the joystick is disconnected or until the library is terminated.</p> | ||
422 | <p >The initial value of the pointer is <code>NULL</code>.</p> | ||
423 | <h2><a class="anchor" id="joystick_event"></a> | ||
424 | Joystick configuration changes</h2> | ||
425 | <p >If you wish to be notified when a joystick is connected or disconnected, set a joystick callback.</p> | ||
426 | <div class="fragment"><div class="line"><a class="code hl_function" href="group__input.html#ga2f60a0e5b7bd8d1b7344dc0a7cb32b4c">glfwSetJoystickCallback</a>(joystick_callback);</div> | ||
427 | <div class="ttc" id="agroup__input_html_ga2f60a0e5b7bd8d1b7344dc0a7cb32b4c"><div class="ttname"><a href="group__input.html#ga2f60a0e5b7bd8d1b7344dc0a7cb32b4c">glfwSetJoystickCallback</a></div><div class="ttdeci">GLFWjoystickfun glfwSetJoystickCallback(GLFWjoystickfun callback)</div><div class="ttdoc">Sets the joystick configuration callback.</div></div> | ||
428 | </div><!-- fragment --><p >The callback function receives the ID of the joystick that has been connected and disconnected and the event that occurred.</p> | ||
429 | <div class="fragment"><div class="line"><span class="keywordtype">void</span> joystick_callback(<span class="keywordtype">int</span> jid, <span class="keywordtype">int</span> event)</div> | ||
430 | <div class="line">{</div> | ||
431 | <div class="line"> <span class="keywordflow">if</span> (event == <a class="code hl_define" href="glfw3_8h.html#abe11513fd1ffbee5bb9b173f06028b9e">GLFW_CONNECTED</a>)</div> | ||
432 | <div class="line"> {</div> | ||
433 | <div class="line"> <span class="comment">// The joystick was connected</span></div> | ||
434 | <div class="line"> }</div> | ||
435 | <div class="line"> <span class="keywordflow">else</span> <span class="keywordflow">if</span> (event == <a class="code hl_define" href="glfw3_8h.html#aab64b25921ef21d89252d6f0a71bfc32">GLFW_DISCONNECTED</a>)</div> | ||
436 | <div class="line"> {</div> | ||
437 | <div class="line"> <span class="comment">// The joystick was disconnected</span></div> | ||
438 | <div class="line"> }</div> | ||
439 | <div class="line">}</div> | ||
440 | <div class="ttc" id="aglfw3_8h_html_aab64b25921ef21d89252d6f0a71bfc32"><div class="ttname"><a href="glfw3_8h.html#aab64b25921ef21d89252d6f0a71bfc32">GLFW_DISCONNECTED</a></div><div class="ttdeci">#define GLFW_DISCONNECTED</div><div class="ttdef"><b>Definition:</b> glfw3.h:1108</div></div> | ||
441 | <div class="ttc" id="aglfw3_8h_html_abe11513fd1ffbee5bb9b173f06028b9e"><div class="ttname"><a href="glfw3_8h.html#abe11513fd1ffbee5bb9b173f06028b9e">GLFW_CONNECTED</a></div><div class="ttdeci">#define GLFW_CONNECTED</div><div class="ttdef"><b>Definition:</b> glfw3.h:1107</div></div> | ||
442 | </div><!-- fragment --><p >For joystick connection and disconnection events to be delivered on all platforms, you need to call one of the <a class="el" href="input_guide.html#events">event processing</a> functions. Joystick disconnection may also be detected and the callback called by joystick functions. The function will then return whatever it returns for a disconnected joystick.</p> | ||
443 | <p >Only <a class="el" href="group__input.html#gac6a8e769e18e0bcfa9097793fc2c3978">glfwGetJoystickName</a> and <a class="el" href="group__input.html#ga18cefd7265d1fa04f3fd38a6746db5f3">glfwGetJoystickUserPointer</a> will return useful values for a disconnected joystick and only before the monitor callback returns.</p> | ||
444 | <h2><a class="anchor" id="gamepad"></a> | ||
445 | Gamepad input</h2> | ||
446 | <p >The joystick functions provide unlabeled axes, buttons and hats, with no indication of where they are located on the device. Their order may also vary between platforms even with the same device.</p> | ||
447 | <p >To solve this problem the SDL community crowdsourced the <a href="https://github.com/gabomdq/SDL_GameControllerDB">SDL_GameControllerDB</a> project, a database of mappings from many different devices to an Xbox-like gamepad.</p> | ||
448 | <p >GLFW supports this mapping format and contains a copy of the mappings available at the time of release. See <a class="el" href="input_guide.html#gamepad_mapping">Gamepad mappings</a> for how to update this at runtime. Mappings will be assigned to joysticks automatically any time a joystick is connected or the mappings are updated.</p> | ||
449 | <p >You can check whether a joystick is both present and has a gamepad mapping with <a class="el" href="group__input.html#gad0f676860f329d80f7e47e9f06a96f00">glfwJoystickIsGamepad</a>.</p> | ||
450 | <div class="fragment"><div class="line"><span class="keywordflow">if</span> (<a class="code hl_function" href="group__input.html#gad0f676860f329d80f7e47e9f06a96f00">glfwJoystickIsGamepad</a>(<a class="code hl_define" href="group__joysticks.html#ga6eab65ec88e65e0850ef8413504cb50c">GLFW_JOYSTICK_2</a>))</div> | ||
451 | <div class="line">{</div> | ||
452 | <div class="line"> <span class="comment">// Use as gamepad</span></div> | ||
453 | <div class="line">}</div> | ||
454 | <div class="ttc" id="agroup__input_html_gad0f676860f329d80f7e47e9f06a96f00"><div class="ttname"><a href="group__input.html#gad0f676860f329d80f7e47e9f06a96f00">glfwJoystickIsGamepad</a></div><div class="ttdeci">int glfwJoystickIsGamepad(int jid)</div><div class="ttdoc">Returns whether the specified joystick has a gamepad mapping.</div></div> | ||
455 | <div class="ttc" id="agroup__joysticks_html_ga6eab65ec88e65e0850ef8413504cb50c"><div class="ttname"><a href="group__joysticks.html#ga6eab65ec88e65e0850ef8413504cb50c">GLFW_JOYSTICK_2</a></div><div class="ttdeci">#define GLFW_JOYSTICK_2</div><div class="ttdef"><b>Definition:</b> glfw3.h:594</div></div> | ||
456 | </div><!-- fragment --><p >If you are only interested in gamepad input you can use this function instead of <a class="el" href="group__input.html#gaed0966cee139d815317f9ffcba64c9f1">glfwJoystickPresent</a>.</p> | ||
457 | <p >You can query the human-readable name provided by the gamepad mapping with <a class="el" href="group__input.html#ga8aea73a1a25cc6c0486a617019f56728">glfwGetGamepadName</a>. This may or may not be the same as the <a class="el" href="input_guide.html#joystick_name">joystick name</a>.</p> | ||
458 | <div class="fragment"><div class="line"><span class="keyword">const</span> <span class="keywordtype">char</span>* name = <a class="code hl_function" href="group__input.html#ga8aea73a1a25cc6c0486a617019f56728">glfwGetGamepadName</a>(<a class="code hl_define" href="group__joysticks.html#ga20a9f4f3aaefed9ea5e66072fc588b87">GLFW_JOYSTICK_7</a>);</div> | ||
459 | <div class="ttc" id="agroup__input_html_ga8aea73a1a25cc6c0486a617019f56728"><div class="ttname"><a href="group__input.html#ga8aea73a1a25cc6c0486a617019f56728">glfwGetGamepadName</a></div><div class="ttdeci">const char * glfwGetGamepadName(int jid)</div><div class="ttdoc">Returns the human-readable gamepad name for the specified joystick.</div></div> | ||
460 | </div><!-- fragment --><p >To retrieve the gamepad state of a joystick, call <a class="el" href="group__input.html#gadccddea8bce6113fa459de379ddaf051">glfwGetGamepadState</a>.</p> | ||
461 | <div class="fragment"><div class="line"><a class="code hl_struct" href="structGLFWgamepadstate.html">GLFWgamepadstate</a> state;</div> | ||
462 | <div class="line"> </div> | ||
463 | <div class="line"><span class="keywordflow">if</span> (<a class="code hl_function" href="group__input.html#gadccddea8bce6113fa459de379ddaf051">glfwGetGamepadState</a>(<a class="code hl_define" href="group__joysticks.html#gae6f3eedfeb42424c2f5e3161efb0b654">GLFW_JOYSTICK_3</a>, &state))</div> | ||
464 | <div class="line">{</div> | ||
465 | <div class="line"> <span class="keywordflow">if</span> (state.<a class="code hl_variable" href="structGLFWgamepadstate.html#a27e9896b51c65df15fba2c7139bfdb9a">buttons</a>[<a class="code hl_define" href="group__gamepad__buttons.html#gae055a12fbf4b48b5954c8e1cd129b810">GLFW_GAMEPAD_BUTTON_A</a>])</div> | ||
466 | <div class="line"> {</div> | ||
467 | <div class="line"> input_jump();</div> | ||
468 | <div class="line"> }</div> | ||
469 | <div class="line"> </div> | ||
470 | <div class="line"> input_speed(state.<a class="code hl_variable" href="structGLFWgamepadstate.html#a8b2c8939b1d31458de5359998375c189">axes</a>[<a class="code hl_define" href="group__gamepad__axes.html#ga121a7d5d20589a423cd1634dd6ee6eab">GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER</a>]);</div> | ||
471 | <div class="line">}</div> | ||
472 | <div class="ttc" id="agroup__gamepad__axes_html_ga121a7d5d20589a423cd1634dd6ee6eab"><div class="ttname"><a href="group__gamepad__axes.html#ga121a7d5d20589a423cd1634dd6ee6eab">GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER</a></div><div class="ttdeci">#define GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER</div><div class="ttdef"><b>Definition:</b> glfw3.h:654</div></div> | ||
473 | <div class="ttc" id="agroup__gamepad__buttons_html_gae055a12fbf4b48b5954c8e1cd129b810"><div class="ttname"><a href="group__gamepad__buttons.html#gae055a12fbf4b48b5954c8e1cd129b810">GLFW_GAMEPAD_BUTTON_A</a></div><div class="ttdeci">#define GLFW_GAMEPAD_BUTTON_A</div><div class="ttdef"><b>Definition:</b> glfw3.h:619</div></div> | ||
474 | <div class="ttc" id="agroup__input_html_gadccddea8bce6113fa459de379ddaf051"><div class="ttname"><a href="group__input.html#gadccddea8bce6113fa459de379ddaf051">glfwGetGamepadState</a></div><div class="ttdeci">int glfwGetGamepadState(int jid, GLFWgamepadstate *state)</div><div class="ttdoc">Retrieves the state of the specified joystick remapped as a gamepad.</div></div> | ||
475 | <div class="ttc" id="astructGLFWgamepadstate_html"><div class="ttname"><a href="structGLFWgamepadstate.html">GLFWgamepadstate</a></div><div class="ttdoc">Gamepad input state.</div><div class="ttdef"><b>Definition:</b> glfw3.h:1746</div></div> | ||
476 | <div class="ttc" id="astructGLFWgamepadstate_html_a27e9896b51c65df15fba2c7139bfdb9a"><div class="ttname"><a href="structGLFWgamepadstate.html#a27e9896b51c65df15fba2c7139bfdb9a">GLFWgamepadstate::buttons</a></div><div class="ttdeci">unsigned char buttons[15]</div><div class="ttdef"><b>Definition:</b> glfw3.h:1750</div></div> | ||
477 | <div class="ttc" id="astructGLFWgamepadstate_html_a8b2c8939b1d31458de5359998375c189"><div class="ttname"><a href="structGLFWgamepadstate.html#a8b2c8939b1d31458de5359998375c189">GLFWgamepadstate::axes</a></div><div class="ttdeci">float axes[6]</div><div class="ttdef"><b>Definition:</b> glfw3.h:1754</div></div> | ||
478 | </div><!-- fragment --><p >The <a class="el" href="structGLFWgamepadstate.html">GLFWgamepadstate</a> struct has two arrays; one for button states and one for axis states. The values for each button and axis are the same as for the <a class="el" href="group__input.html#ga5ffe34739d3dc97efe432ed2d81d9938">glfwGetJoystickButtons</a> and <a class="el" href="group__input.html#gaeb1c0191d3140a233a682987c61eb408">glfwGetJoystickAxes</a> functions, i.e. <code>GLFW_PRESS</code> or <code>GLFW_RELEASE</code> for buttons and -1.0 to 1.0 inclusive for axes.</p> | ||
479 | <p >The sizes of the arrays and the positions within each array are fixed.</p> | ||
480 | <p >The <a class="el" href="group__gamepad__buttons.html">button indices</a> are <code>GLFW_GAMEPAD_BUTTON_A</code>, <code>GLFW_GAMEPAD_BUTTON_B</code>, <code>GLFW_GAMEPAD_BUTTON_X</code>, <code>GLFW_GAMEPAD_BUTTON_Y</code>, <code>GLFW_GAMEPAD_BUTTON_LEFT_BUMPER</code>, <code>GLFW_GAMEPAD_BUTTON_RIGHT_BUMPER</code>, <code>GLFW_GAMEPAD_BUTTON_BACK</code>, <code>GLFW_GAMEPAD_BUTTON_START</code>, <code>GLFW_GAMEPAD_BUTTON_GUIDE</code>, <code>GLFW_GAMEPAD_BUTTON_LEFT_THUMB</code>, <code>GLFW_GAMEPAD_BUTTON_RIGHT_THUMB</code>, <code>GLFW_GAMEPAD_BUTTON_DPAD_UP</code>, <code>GLFW_GAMEPAD_BUTTON_DPAD_RIGHT</code>, <code>GLFW_GAMEPAD_BUTTON_DPAD_DOWN</code> and <code>GLFW_GAMEPAD_BUTTON_DPAD_LEFT</code>.</p> | ||
481 | <p >For those who prefer, there are also the <code>GLFW_GAMEPAD_BUTTON_CROSS</code>, <code>GLFW_GAMEPAD_BUTTON_CIRCLE</code>, <code>GLFW_GAMEPAD_BUTTON_SQUARE</code> and <code>GLFW_GAMEPAD_BUTTON_TRIANGLE</code> aliases for the A, B, X and Y button indices.</p> | ||
482 | <p >The <a class="el" href="group__gamepad__axes.html">axis indices</a> are <code>GLFW_GAMEPAD_AXIS_LEFT_X</code>, <code>GLFW_GAMEPAD_AXIS_LEFT_Y</code>, <code>GLFW_GAMEPAD_AXIS_RIGHT_X</code>, <code>GLFW_GAMEPAD_AXIS_RIGHT_Y</code>, <code>GLFW_GAMEPAD_AXIS_LEFT_TRIGGER</code> and <code>GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER</code>.</p> | ||
483 | <p >The <code>GLFW_GAMEPAD_BUTTON_LAST</code> and <code>GLFW_GAMEPAD_AXIS_LAST</code> constants equal the largest available index for each array.</p> | ||
484 | <h2><a class="anchor" id="gamepad_mapping"></a> | ||
485 | Gamepad mappings</h2> | ||
486 | <p >GLFW contains a copy of the mappings available in <a href="https://github.com/gabomdq/SDL_GameControllerDB">SDL_GameControllerDB</a> at the time of release. Newer ones can be added at runtime with <a class="el" href="group__input.html#gaed5104612f2fa8e66aa6e846652ad00f">glfwUpdateGamepadMappings</a>.</p> | ||
487 | <div class="fragment"><div class="line"><span class="keyword">const</span> <span class="keywordtype">char</span>* mappings = load_file_contents(<span class="stringliteral">"game/data/gamecontrollerdb.txt"</span>);</div> | ||
488 | <div class="line"> </div> | ||
489 | <div class="line"><a class="code hl_function" href="group__input.html#gaed5104612f2fa8e66aa6e846652ad00f">glfwUpdateGamepadMappings</a>(mappings);</div> | ||
490 | <div class="ttc" id="agroup__input_html_gaed5104612f2fa8e66aa6e846652ad00f"><div class="ttname"><a href="group__input.html#gaed5104612f2fa8e66aa6e846652ad00f">glfwUpdateGamepadMappings</a></div><div class="ttdeci">int glfwUpdateGamepadMappings(const char *string)</div><div class="ttdoc">Adds the specified SDL_GameControllerDB gamepad mappings.</div></div> | ||
491 | </div><!-- fragment --><p >This function supports everything from single lines up to and including the unmodified contents of the whole <code>gamecontrollerdb.txt</code> file.</p> | ||
492 | <p >If you are compiling GLFW from source with CMake you can update the built-in mappings by building the <em>update_mappings</em> target. This runs the <code>GenerateMappings.cmake</code> CMake script, which downloads <code>gamecontrollerdb.txt</code> and regenerates the <code>mappings.h</code> header file.</p> | ||
493 | <p >Below is a description of the mapping format. Please keep in mind that <b>this description is not authoritative</b>. The format is defined by the SDL and SDL_GameControllerDB projects and their documentation and code takes precedence.</p> | ||
494 | <p >Each mapping is a single line of comma-separated values describing the GUID, name and layout of the gamepad. Lines that do not begin with a hexadecimal digit are ignored.</p> | ||
495 | <p >The first value is always the gamepad GUID, a 32 character long hexadecimal string that typically identifies its make, model, revision and the type of connection to the computer. When this information is not available, the GUID is generated using the gamepad name. GLFW uses the SDL 2.0.5+ GUID format but can convert from the older formats.</p> | ||
496 | <p >The second value is always the human-readable name of the gamepad.</p> | ||
497 | <p >All subsequent values are in the form <code><field>:<value></code> and describe the layout of the mapping. These fields may not all be present and may occur in any order.</p> | ||
498 | <p >The button fields are <code>a</code>, <code>b</code>, <code>c</code>, <code>d</code>, <code>back</code>, <code>start</code>, <code>guide</code>, <code>dpup</code>, <code>dpright</code>, <code>dpdown</code>, <code>dpleft</code>, <code>leftshoulder</code>, <code>rightshoulder</code>, <code>leftstick</code> and <code>rightstick</code>.</p> | ||
499 | <p >The axis fields are <code>leftx</code>, <code>lefty</code>, <code>rightx</code>, <code>righty</code>, <code>lefttrigger</code> and <code>righttrigger</code>.</p> | ||
500 | <p >The value of an axis or button field can be a joystick button, a joystick axis, a hat bitmask or empty. Joystick buttons are specified as <code>bN</code>, for example <code>b2</code> for the third button. Joystick axes are specified as <code>aN</code>, for example <code>a7</code> for the eighth button. Joystick hat bit masks are specified as <code>hN.N</code>, for example <code>h0.8</code> for left on the first hat. More than one bit may be set in the mask.</p> | ||
501 | <p >Before an axis there may be a <code>+</code> or <code>-</code> range modifier, for example <code>+a3</code> for the positive half of the fourth axis. This restricts input to only the positive or negative halves of the joystick axis. After an axis or half-axis there may be the <code>~</code> inversion modifier, for example <code>a2~</code> or <code>-a7~</code>. This negates the values of the gamepad axis.</p> | ||
502 | <p >The hat bit mask match the <a class="el" href="group__hat__state.html">hat states</a> in the joystick functions.</p> | ||
503 | <p >There is also the special <code>platform</code> field that specifies which platform the mapping is valid for. Possible values are <code>Windows</code>, <code>Mac OS X</code> and <code>Linux</code>.</p> | ||
504 | <p >Below is an example of what a gamepad mapping might look like. It is the one built into GLFW for Xbox controllers accessed via the XInput API on Windows. This example has been broken into several lines to fit on the page, but real gamepad mappings must be a single line.</p> | ||
505 | <div class="fragment"><div class="line">78696e70757401000000000000000000,XInput Gamepad (GLFW),platform:Windows,a:b0,</div> | ||
506 | <div class="line">b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,leftstick:b8,</div> | ||
507 | <div class="line">rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,</div> | ||
508 | <div class="line">righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,</div> | ||
509 | </div><!-- fragment --><dl class="section note"><dt>Note</dt><dd>GLFW does not yet support the output range and modifiers <code>+</code> and <code>-</code> that were recently added to SDL. The input modifiers <code>+</code>, <code>-</code> and <code>~</code> are supported and described above.</dd></dl> | ||
510 | <h1><a class="anchor" id="time"></a> | ||
511 | Time input</h1> | ||
512 | <p >GLFW provides high-resolution time input, in seconds, with <a class="el" href="group__input.html#gaa6cf4e7a77158a3b8fd00328b1720a4a">glfwGetTime</a>.</p> | ||
513 | <div class="fragment"><div class="line"><span class="keywordtype">double</span> seconds = <a class="code hl_function" href="group__input.html#gaa6cf4e7a77158a3b8fd00328b1720a4a">glfwGetTime</a>();</div> | ||
514 | <div class="ttc" id="agroup__input_html_gaa6cf4e7a77158a3b8fd00328b1720a4a"><div class="ttname"><a href="group__input.html#gaa6cf4e7a77158a3b8fd00328b1720a4a">glfwGetTime</a></div><div class="ttdeci">double glfwGetTime(void)</div><div class="ttdoc">Returns the GLFW time.</div></div> | ||
515 | </div><!-- fragment --><p >It returns the number of seconds since the library was initialized with <a class="el" href="group__init.html#ga317aac130a235ab08c6db0834907d85e">glfwInit</a>. The platform-specific time sources used typically have micro- or nanosecond resolution.</p> | ||
516 | <p >You can modify the base time with <a class="el" href="group__input.html#gaf59589ef6e8b8c8b5ad184b25afd4dc0">glfwSetTime</a>.</p> | ||
517 | <div class="fragment"><div class="line"><a class="code hl_function" href="group__input.html#gaf59589ef6e8b8c8b5ad184b25afd4dc0">glfwSetTime</a>(4.0);</div> | ||
518 | <div class="ttc" id="agroup__input_html_gaf59589ef6e8b8c8b5ad184b25afd4dc0"><div class="ttname"><a href="group__input.html#gaf59589ef6e8b8c8b5ad184b25afd4dc0">glfwSetTime</a></div><div class="ttdeci">void glfwSetTime(double time)</div><div class="ttdoc">Sets the GLFW time.</div></div> | ||
519 | </div><!-- fragment --><p >This sets the time to the specified time, in seconds, and it continues to count from there.</p> | ||
520 | <p >You can also access the raw timer used to implement the functions above, with <a class="el" href="group__input.html#ga09b2bd37d328e0b9456c7ec575cc26aa">glfwGetTimerValue</a>.</p> | ||
521 | <div class="fragment"><div class="line">uint64_t value = <a class="code hl_function" href="group__input.html#ga09b2bd37d328e0b9456c7ec575cc26aa">glfwGetTimerValue</a>();</div> | ||
522 | <div class="ttc" id="agroup__input_html_ga09b2bd37d328e0b9456c7ec575cc26aa"><div class="ttname"><a href="group__input.html#ga09b2bd37d328e0b9456c7ec575cc26aa">glfwGetTimerValue</a></div><div class="ttdeci">uint64_t glfwGetTimerValue(void)</div><div class="ttdoc">Returns the current value of the raw timer.</div></div> | ||
523 | </div><!-- fragment --><p >This value is in 1 / frequency seconds. The frequency of the raw timer varies depending on the operating system and hardware. You can query the frequency, in Hz, with <a class="el" href="group__input.html#ga3289ee876572f6e91f06df3a24824443">glfwGetTimerFrequency</a>.</p> | ||
524 | <div class="fragment"><div class="line">uint64_t frequency = <a class="code hl_function" href="group__input.html#ga3289ee876572f6e91f06df3a24824443">glfwGetTimerFrequency</a>();</div> | ||
525 | <div class="ttc" id="agroup__input_html_ga3289ee876572f6e91f06df3a24824443"><div class="ttname"><a href="group__input.html#ga3289ee876572f6e91f06df3a24824443">glfwGetTimerFrequency</a></div><div class="ttdeci">uint64_t glfwGetTimerFrequency(void)</div><div class="ttdoc">Returns the frequency, in Hz, of the raw timer.</div></div> | ||
526 | </div><!-- fragment --><h1><a class="anchor" id="clipboard"></a> | ||
527 | Clipboard input and output</h1> | ||
528 | <p >If the system clipboard contains a UTF-8 encoded string or if it can be converted to one, you can retrieve it with <a class="el" href="group__input.html#ga71a5b20808ea92193d65c21b82580355">glfwGetClipboardString</a>. See the reference documentation for the lifetime of the returned string.</p> | ||
529 | <div class="fragment"><div class="line"><span class="keyword">const</span> <span class="keywordtype">char</span>* text = <a class="code hl_function" href="group__input.html#ga71a5b20808ea92193d65c21b82580355">glfwGetClipboardString</a>(NULL);</div> | ||
530 | <div class="line"><span class="keywordflow">if</span> (text)</div> | ||
531 | <div class="line">{</div> | ||
532 | <div class="line"> insert_text(text);</div> | ||
533 | <div class="line">}</div> | ||
534 | <div class="ttc" id="agroup__input_html_ga71a5b20808ea92193d65c21b82580355"><div class="ttname"><a href="group__input.html#ga71a5b20808ea92193d65c21b82580355">glfwGetClipboardString</a></div><div class="ttdeci">const char * glfwGetClipboardString(GLFWwindow *window)</div><div class="ttdoc">Returns the contents of the clipboard as a string.</div></div> | ||
535 | </div><!-- fragment --><p >If the clipboard is empty or if its contents could not be converted, <code>NULL</code> is returned.</p> | ||
536 | <p >The contents of the system clipboard can be set to a UTF-8 encoded string with <a class="el" href="group__input.html#gaba1f022c5eb07dfac421df34cdcd31dd">glfwSetClipboardString</a>.</p> | ||
537 | <div class="fragment"><div class="line"><a class="code hl_function" href="group__input.html#gaba1f022c5eb07dfac421df34cdcd31dd">glfwSetClipboardString</a>(NULL, <span class="stringliteral">"A string with words in it"</span>);</div> | ||
538 | <div class="ttc" id="agroup__input_html_gaba1f022c5eb07dfac421df34cdcd31dd"><div class="ttname"><a href="group__input.html#gaba1f022c5eb07dfac421df34cdcd31dd">glfwSetClipboardString</a></div><div class="ttdeci">void glfwSetClipboardString(GLFWwindow *window, const char *string)</div><div class="ttdoc">Sets the clipboard to the specified string.</div></div> | ||
539 | </div><!-- fragment --><h1><a class="anchor" id="path_drop"></a> | ||
540 | Path drop input</h1> | ||
541 | <p >If you wish to receive the paths of files and/or directories dropped on a window, set a file drop callback.</p> | ||
542 | <div class="fragment"><div class="line"><a class="code hl_function" href="group__input.html#gab773f0ee0a07cff77a210cea40bc1f6b">glfwSetDropCallback</a>(window, drop_callback);</div> | ||
543 | <div class="ttc" id="agroup__input_html_gab773f0ee0a07cff77a210cea40bc1f6b"><div class="ttname"><a href="group__input.html#gab773f0ee0a07cff77a210cea40bc1f6b">glfwSetDropCallback</a></div><div class="ttdeci">GLFWdropfun glfwSetDropCallback(GLFWwindow *window, GLFWdropfun callback)</div><div class="ttdoc">Sets the path drop callback.</div></div> | ||
544 | </div><!-- fragment --><p >The callback function receives an array of paths encoded as UTF-8.</p> | ||
545 | <div class="fragment"><div class="line"><span class="keywordtype">void</span> drop_callback(<a class="code hl_typedef" href="group__window.html#ga3c96d80d363e67d13a41b5d1821f3242">GLFWwindow</a>* window, <span class="keywordtype">int</span> count, <span class="keyword">const</span> <span class="keywordtype">char</span>** paths)</div> | ||
546 | <div class="line">{</div> | ||
547 | <div class="line"> <span class="keywordtype">int</span> i;</div> | ||
548 | <div class="line"> <span class="keywordflow">for</span> (i = 0; i < count; i++)</div> | ||
549 | <div class="line"> handle_dropped_file(paths[i]);</div> | ||
550 | <div class="line">}</div> | ||
551 | </div><!-- fragment --><p >The path array and its strings are only valid until the file drop callback returns, as they may have been generated specifically for that event. You need to make a deep copy of the array if you want to keep the paths. </p> | ||
552 | </div></div><!-- contents --> | ||
553 | </div><!-- PageDoc --> | ||
554 | <address class="footer"> | ||
555 | <p> | ||
556 | Last update on Thu Oct 28 2021 for GLFW 3.3.5 | ||
557 | </p> | ||
558 | </address> | ||
559 | </body> | ||
560 | </html> | ||