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
293bdf05
Commit
293bdf05
authored
4 years ago
by
NikolaBabic
Browse files
Options
Downloads
Patches
Plain Diff
Removed unnecessary thread method.
Added ability to stop runnable loop.
parent
d5d37ac7
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
+25
-16
25 additions, 16 deletions
src/model/OSInterface.java
with
25 additions
and
16 deletions
src/model/OSInterface.java
+
25
−
16
View file @
293bdf05
...
...
@@ -17,18 +17,17 @@ public class OSInterface implements HotkeyDetector, HotkeyRegistration, InputEmu
private
HashMap
<
Integer
,
Hotkey
>
registeredKeys
;
private
HashMap
<
Integer
,
Boolean
>
pressedKeys
;
private
WinUser
.
MSG
msg
;
/** Signal for the OSInterface to stop it's thread runnable. **/
private
boolean
stop
=
false
;
/** Stack for hotkeys to be registered. */
private
Stack
<
Hotkey
>
hotkeyRegStack
;
/** Stack for hotkey presses to be checked. */
private
Stack
<
Integer
>
wasPressedStack
;
private
OSInterface
()
{
registeredKeys
=
new
HashMap
<>();
pressedKeys
=
new
HashMap
<>();
msg
=
new
WinUser
.
MSG
();
hotkeyRegStack
=
new
Stack
<>();
wasPressedStack
=
new
Stack
<>();
}
/**
...
...
@@ -41,15 +40,26 @@ public class OSInterface implements HotkeyDetector, HotkeyRegistration, InputEmu
return
instance
;
}
/**
* Stops the OSInterface runnable.
* Only should be called when the program is shutting down.
*/
public
void
stop
()
{
this
.
stop
=
true
;
}
/**
* Main thread for checking messages and processing requests.
*/
public
void
run
()
{
boolean
isMsg
=
user32
.
PeekMessage
(
msg
,
null
,
0
,
0
,
1
);
while
(
msg
.
message
!=
User32
.
WM_QUIT
)
{
while
(
msg
.
message
!=
User32
.
WM_QUIT
&&
!
stop
)
{
if
(
isMsg
)
{
if
(
msg
.
message
==
User32
.
WM_HOTKEY
)
{
int
keyPressed
=
msg
.
wParam
.
intValue
();
if
(
registeredKeys
.
containsKey
(
keyPressed
))
{
pressedKeys
.
put
(
keyPressed
,
true
);
}
}
}
...
...
@@ -97,10 +107,11 @@ public class OSInterface implements HotkeyDetector, HotkeyRegistration, InputEmu
return
success
;
}
// TODO Add thread version.
@Override
public
boolean
unregisterHotkey
(
int
id
)
{
if
(
!
registeredKeys
.
containsKey
(
id
))
return
tru
e
;
if
(
registeredKeys
.
containsKey
(
id
)
||
registeredKeys
.
isEmpty
()
)
return
fals
e
;
boolean
success
=
user32
.
UnregisterHotKey
(
hwnd
.
getPointer
(),
id
);
if
(
success
)
...
...
@@ -116,16 +127,14 @@ public class OSInterface implements HotkeyDetector, HotkeyRegistration, InputEmu
@Override
public
boolean
wasPressed
(
int
id
)
{
return
false
;
}
if
(!
registeredKeys
.
containsKey
(
id
)
||
pressedKeys
.
isEmpty
())
return
false
;
/**
* The logic for wasPressed that will run on the thread.
* @param id The hotkey id to be checked.
* @return If the hotkey was pressed.
*/
public
boolean
wasPressedThread
(
int
id
)
{
return
false
;
boolean
pressed
=
pressedKeys
.
get
(
id
);
// Set the hotkey back to default not pressed.
pressedKeys
.
put
(
id
,
false
);
return
pressed
;
}
@Override
...
...
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