Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Sinister Zeta Project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sinister Zeta
Sinister Zeta Project
Commits
65c8d3d9
Commit
65c8d3d9
authored
4 years ago
by
NikolaBabic
Browse files
Options
Downloads
Patches
Plain Diff
Added barebones OSInterface with hotkey registration.
parent
da21840b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!45
Prototype to Master for Milestone 5
,
!41
Feature OS interface
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/model/OSInterface.java
+76
-0
76 additions, 0 deletions
src/model/OSInterface.java
with
76 additions
and
0 deletions
src/model/OSInterface.java
0 → 100644
+
76
−
0
View file @
65c8d3d9
package
model
;
import
com.sun.jna.platform.win32.User32
;
import
com.sun.jna.platform.win32.WinDef
;
import
java.util.HashMap
;
/** Singleton class which interfaces with windows. */
public
class
OSInterface
implements
HotkeyDetector
,
HotkeyRegistration
,
InputEmulator
,
OSSettingsWriter
{
private
static
OSInterface
instance
=
null
;
private
User32
user32
=
User32
.
INSTANCE
;
private
WinDef
.
HWND
hwnd
;
private
HashMap
<
Integer
,
Hotkey
>
registeredKeys
;
private
OSInterface
()
{
registeredKeys
=
new
HashMap
<>();
}
/**
* Gets the OSInterface instance.
*/
public
static
OSInterface
getInstance
()
{
if
(
instance
==
null
)
instance
=
new
OSInterface
();
return
instance
;
}
/**
* Sets the HWND to use for interfacing with the OS.
* @param hwnd The HWND of a window.
*/
public
void
setHWND
(
WinDef
.
HWND
hwnd
)
{
this
.
hwnd
=
hwnd
;
}
@Override
public
boolean
registerHotkey
(
Hotkey
hotkey
)
{
if
(
registeredKeys
.
containsKey
(
hotkey
.
getID
()))
return
false
;
boolean
success
=
user32
.
RegisterHotKey
(
hwnd
,
hotkey
.
getID
(),
hotkey
.
getModifier
(),
hotkey
.
getKeyCode
());
if
(
success
)
registeredKeys
.
put
(
hotkey
.
getID
(),
hotkey
);
return
success
;
}
@Override
public
boolean
unregisterHotkey
(
int
id
)
{
if
(!
registeredKeys
.
containsKey
(
id
))
return
true
;
boolean
success
=
user32
.
UnregisterHotKey
(
hwnd
.
getPointer
(),
id
);
if
(
success
)
registeredKeys
.
remove
(
id
);
return
success
;
}
@Override
public
boolean
setMouseSpeed
(
int
speed
)
{
return
false
;
}
@Override
public
boolean
wasPressed
(
int
id
)
{
return
false
;
}
@Override
public
void
sendKey
(
int
keyCode
,
boolean
release
)
{
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment