Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libSDL
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PocketInsanity
libSDL
Commits
ee56d1a7
Commit
ee56d1a7
authored
Oct 25, 2011
by
Sam Lantinga
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added SDL_GetScancodeFromName() and SDL_GetKeyFromName()
parent
b285f501
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
105 additions
and
6 deletions
+105
-6
SDL_keyboard.h
include/SDL_keyboard.h
+21
-5
SDL_keyboard.c
src/events/SDL_keyboard.c
+83
-0
SDL_string.c
src/stdlib/SDL_string.c
+1
-1
No files found.
include/SDL_keyboard.h
View file @
ee56d1a7
...
@@ -111,15 +111,22 @@ extern DECLSPEC SDL_Scancode SDLCALL SDL_GetScancodeFromKey(SDL_Keycode key);
...
@@ -111,15 +111,22 @@ extern DECLSPEC SDL_Scancode SDLCALL SDL_GetScancodeFromKey(SDL_Keycode key);
/**
/**
* \brief Get a human-readable name for a scancode.
* \brief Get a human-readable name for a scancode.
*
*
* \return A pointer to a UTF-8 string that stays valid at least until the next
* \return A pointer to the name for the scancode.
* call to this function. If you need it around any longer, you must
* If the scancode doesn't have a name, this function returns
* copy it. If the scancode doesn't have a name, this function returns
* an empty string ("").
* an empty string ("").
*
*
* \sa SDL_Scancode
* \sa SDL_Scancode
*/
*/
extern
DECLSPEC
const
char
*
SDLCALL
SDL_GetScancodeName
(
SDL_Scancode
extern
DECLSPEC
const
char
*
SDLCALL
SDL_GetScancodeName
(
SDL_Scancode
scancode
);
scancode
);
/**
* \brief Get a scancode from a human-readable name
*
* \return scancode, or SDL_SCANCODE_UNKNOWN if the name wasn't recognized
*
* \sa SDL_Scancode
*/
extern
DECLSPEC
SDL_Scancode
SDLCALL
SDL_GetScancodeFromName
(
const
char
*
name
);
/**
/**
* \brief Get a human-readable name for a key.
* \brief Get a human-readable name for a key.
...
@@ -133,6 +140,15 @@ extern DECLSPEC const char *SDLCALL SDL_GetScancodeName(SDL_Scancode
...
@@ -133,6 +140,15 @@ extern DECLSPEC const char *SDLCALL SDL_GetScancodeName(SDL_Scancode
*/
*/
extern
DECLSPEC
const
char
*
SDLCALL
SDL_GetKeyName
(
SDL_Keycode
key
);
extern
DECLSPEC
const
char
*
SDLCALL
SDL_GetKeyName
(
SDL_Keycode
key
);
/**
* \brief Get a key code from a human-readable name
*
* \return key code, or SDLK_UNKNOWN if the name wasn't recognized
*
* \sa SDL_Keycode
*/
extern
DECLSPEC
SDL_Keycode
SDLCALL
SDL_GetKeyFromName
(
const
char
*
name
);
/**
/**
* \brief Start accepting Unicode text input events.
* \brief Start accepting Unicode text input events.
*
*
...
...
src/events/SDL_keyboard.c
View file @
ee56d1a7
...
@@ -854,6 +854,23 @@ SDL_GetKeyFromScancode(SDL_Scancode scancode)
...
@@ -854,6 +854,23 @@ SDL_GetKeyFromScancode(SDL_Scancode scancode)
return
keyboard
->
keymap
[
scancode
];
return
keyboard
->
keymap
[
scancode
];
}
}
SDL_Keycode
SDL_GetKeycodeFromName
(
const
char
*
name
)
{
int
i
;
if
(
!
name
||
!*
name
)
{
return
SDL_SCANCODE_UNKNOWN
;
}
for
(
i
=
0
;
i
<
SDL_arraysize
(
SDL_scancode_names
);
++
i
)
{
if
(
SDL_strcasecmp
(
name
,
SDL_scancode_names
[
i
])
==
0
)
{
return
(
SDL_Scancode
)
i
;
}
}
return
SDL_SCANCODE_UNKNOWN
;
}
SDL_Scancode
SDL_Scancode
SDL_GetScancodeFromKey
(
SDL_Keycode
key
)
SDL_GetScancodeFromKey
(
SDL_Keycode
key
)
{
{
...
@@ -880,6 +897,25 @@ SDL_GetScancodeName(SDL_Scancode scancode)
...
@@ -880,6 +897,25 @@ SDL_GetScancodeName(SDL_Scancode scancode)
return
""
;
return
""
;
}
}
SDL_Scancode
SDL_GetScancodeFromName
(
const
char
*
name
)
{
int
i
;
if
(
!
name
||
!*
name
)
{
return
SDL_SCANCODE_UNKNOWN
;
}
for
(
i
=
0
;
i
<
SDL_arraysize
(
SDL_scancode_names
);
++
i
)
{
if
(
!
SDL_scancode_names
[
i
])
{
continue
;
}
if
(
SDL_strcasecmp
(
name
,
SDL_scancode_names
[
i
])
==
0
)
{
return
(
SDL_Scancode
)
i
;
}
}
return
SDL_SCANCODE_UNKNOWN
;
}
const
char
*
const
char
*
SDL_GetKeyName
(
SDL_Keycode
key
)
SDL_GetKeyName
(
SDL_Keycode
key
)
{
{
...
@@ -919,4 +955,51 @@ SDL_GetKeyName(SDL_Keycode key)
...
@@ -919,4 +955,51 @@ SDL_GetKeyName(SDL_Keycode key)
}
}
}
}
SDL_Keycode
SDL_GetKeyFromName
(
const
char
*
name
)
{
SDL_Keycode
key
;
/* If it's a single UTF-8 character, then that's the keycode itself */
key
=
*
(
const
unsigned
char
*
)
name
;
if
(
key
>=
0xF0
)
{
if
(
SDL_strlen
(
name
)
==
4
)
{
int
i
=
0
;
key
=
(
Uint16
)(
name
[
i
]
&
0x07
)
<<
18
;
key
|=
(
Uint16
)(
name
[
++
i
]
&
0x3F
)
<<
12
;
key
|=
(
Uint16
)(
name
[
++
i
]
&
0x3F
)
<<
6
;
key
|=
(
Uint16
)(
name
[
++
i
]
&
0x3F
);
return
key
;
}
return
SDLK_UNKNOWN
;
}
else
if
(
key
>=
0xE0
)
{
if
(
SDL_strlen
(
name
)
==
3
)
{
int
i
=
0
;
key
=
(
Uint16
)(
name
[
i
]
&
0x0F
)
<<
12
;
key
|=
(
Uint16
)(
name
[
++
i
]
&
0x3F
)
<<
6
;
key
|=
(
Uint16
)(
name
[
++
i
]
&
0x3F
);
return
key
;
}
return
SDLK_UNKNOWN
;
}
else
if
(
key
>=
0xC0
)
{
if
(
SDL_strlen
(
name
)
==
2
)
{
int
i
=
0
;
key
=
(
Uint16
)(
name
[
i
]
&
0x1F
)
<<
6
;
key
|=
(
Uint16
)(
name
[
++
i
]
&
0x3F
);
return
key
;
}
return
SDLK_UNKNOWN
;
}
else
{
if
(
SDL_strlen
(
name
)
==
1
)
{
if
(
key
>=
'A'
&&
key
<=
'Z'
)
{
key
+=
32
;
}
return
key
;
}
/* Get the scancode for this name, and the associated keycode */
return
SDL_default_keymap
[
SDL_GetScancodeFromName
(
name
)];
}
}
/* vi: set ts=4 sw=4 expandtab: */
/* vi: set ts=4 sw=4 expandtab: */
src/stdlib/SDL_string.c
View file @
ee56d1a7
...
@@ -33,7 +33,7 @@
...
@@ -33,7 +33,7 @@
int
UTF8_TrailingBytes
(
unsigned
char
c
)
int
UTF8_TrailingBytes
(
unsigned
char
c
)
{
{
if
(
c
>=
0xC0
&&
c
<=
0xDF
)
if
(
c
>=
0xC0
&&
c
<=
0xDF
)
return
1
;
return
1
;
else
if
(
c
>=
0xE0
&&
c
<=
0xEF
)
else
if
(
c
>=
0xE0
&&
c
<=
0xEF
)
return
2
;
return
2
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment