d0f48a6f8055cf1fb60862b837c82bf344a3e0fd
[platform/framework/web/crosswalk-tizen.git] / docs-translations / th-TH / api / global-shortcut.md
1 # globalShortcut
2
3 > Detect keyboard events when the application does not have keyboard focus.
4
5 Process: [Main](../glossary.md#main-process)
6
7 The `globalShortcut` module can register/unregister a global keyboard shortcut
8 with the operating system so that you can customize the operations for various
9 shortcuts.
10
11 **Note:** The shortcut is global; it will work even if the app does
12 not have the keyboard focus. You should not use this module until the `ready`
13 event of the app module is emitted.
14
15 ```javascript
16 const {app, globalShortcut} = require('electron')
17
18 app.on('ready', () => {
19   // Register a 'CommandOrControl+X' shortcut listener.
20   const ret = globalShortcut.register('CommandOrControl+X', () => {
21     console.log('CommandOrControl+X is pressed')
22   })
23
24   if (!ret) {
25     console.log('registration failed')
26   }
27
28   // Check whether a shortcut is registered.
29   console.log(globalShortcut.isRegistered('CommandOrControl+X'))
30 })
31
32 app.on('will-quit', () => {
33   // Unregister a shortcut.
34   globalShortcut.unregister('CommandOrControl+X')
35
36   // Unregister all shortcuts.
37   globalShortcut.unregisterAll()
38 })
39 ```
40
41 ## Methods
42
43 The `globalShortcut` module has the following methods:
44
45 ### `globalShortcut.register(accelerator, callback)`
46
47 * `accelerator` [Accelerator](accelerator.md)
48 * `callback` Function
49
50 Registers a global shortcut of `accelerator`. The `callback` is called when
51 the registered shortcut is pressed by the user.
52
53 When the accelerator is already taken by other applications, this call will
54 silently fail. This behavior is intended by operating systems, since they don't
55 want applications to fight for global shortcuts.
56
57 ### `globalShortcut.isRegistered(accelerator)`
58
59 * `accelerator` [Accelerator](accelerator.md)
60
61 Returns `Boolean` - Whether this application has registered `accelerator`.
62
63 When the accelerator is already taken by other applications, this call will
64 still return `false`. This behavior is intended by operating systems, since they
65 don't want applications to fight for global shortcuts.
66
67 ### `globalShortcut.unregister(accelerator)`
68
69 * `accelerator` [Accelerator](accelerator.md)
70
71 Unregisters the global shortcut of `accelerator`.
72
73 ### `globalShortcut.unregisterAll()`
74
75 Unregisters all of the global shortcuts.