Problem Statement
In WinCC Professional (TIA Portal) and the WinCC Comfort/Advanced runtimes, operators routinely request a single-key horn-acknowledge action so the audible alarm can be silenced without lifting a hand from the keyboard. The natural choice is the F1 key, but several of WinCC's default behaviors work against this requirement:
- The configured horn-acknowledge push button only receives
Keyboard PressandKeyboard Releaseevents while it actually holds the screen focus. - A normal push button does not take the focus when an operator is editing a different object, such as an analog setpoint I/O field, on the same screen.
- Calling
Set_Focus()on the acknowledge button from a script solves the event-dispatch problem but immediately makes the previously focused object (e.g. an analog setpoint) un-editable until the focus is programmatically returned. - Multiple buttons that share the same hotkey collide: WinCC only fires the first one it finds in the object tree.
This article documents four distinct implementation paths that exist in WinCC, isolates the precise root cause for each failure mode, and recommends the configuration that delivers focus-independent horn acknowledgement with zero impact on other I/O objects.
Root Cause: The WinCC Focus and Event Model
WinCC's runtime treats the keyboard as a per-focus input device. The event delivery rules are:
-
Mouse events on a button (
Mouse Click,Mouse Down,Mouse Up) are dispatched regardless of focus, but they only fire when the operator physically uses the pointing device. -
Keyboard events (
Keyboard Press,Keyboard Release) are delivered to the object that currently holds the runtime focus, identified internally through the WinCC object model's focus chain. - A ShortCut property (found under Miscellaneous) on a button object is the one keyboard-related property that does not require focus. WinCC's input dispatcher intercepts the configured F-key at the screen level and routes it to the configured
Mouse Clickevent of the owning button. - Calling
Set_Focus()from a C or VB script transfers focus to the target object and keeps it there. It is not a transient operation; the focus remains with the target object until anotherSet_Focus()call or a mouse click moves it. - Picture windows opened with the
@prefix (e.g.@HornQuit.pdl) are children of the parent picture. A hotkey collision between an object in the picture window and an object in the parent picture will silently disable the lower-priority binding with no error message.
Understanding these rules makes it clear why the simplest implementation (just drop a button, assign a script, and expect F1 to work) fails in practice, and why each of the four documented workarounds addresses a specific symptom rather than the underlying cause.
Method 1: Set_Focus C Script (Use with Caution)
The Set_Focus C function is the legacy approach used in WinCC V7 and remains available in WinCC Professional under TIA Portal V16/V17. It is called from a global C script, commonly from the Open Picture event of a screen that should respond to the horn-acknowledge hotkey.
Example C action bound to a screen's Open Picture event:
// C action: Force focus to the horn-acknowledge button when the screen opens
#include "GlobalDef.h"
void OnOpenPicture(char* lpszPictureName, char* lpszObjectName)
{
// Tag name and button name are project-specific
Set_Focus(lpszPictureName, "BtnHornAck");
return;
}
Failure mode this triggers: once BtnHornAck holds the focus, the Keyboard Press event fires correctly on F1. However, every other input object on the screen loses the ability to receive the cursor. Operators can no longer change an analog alarm setpoint, edit a recipe parameter, or click into a date picker until the focus is moved back manually.
This is the reason the original report states: "when you make enable Set_Focus for a Push Button you can't change anything else."
If Set_Focus must be used, the focus must be programmatically released on every Mouse Click of any other input object. The maintenance cost of this approach makes it unsuitable for screens with more than two or three input fields.
Method 2: Keyboard Polling with getchar()
Because Keyboard Press events require focus, the second workaround reads the keyboard directly from a global C action triggered by a tag change. WinCC's C runtime exposes the standard C library function getchar(), which reads one character from the stdin stream of the runtime process.
This method is implemented as a scheduled C task bound to a global internal tag (e.g. HornActive) that toggles whenever an alarm is raised. The task body is approximately:
// C action: Scheduled task, 100 ms cycle, on HornActive rising edge
#include "GlobalDef.h"
#include <stdio.h>
void PollHornAck(void)
{
static DWORD dwLastChange = 0;
DWORD dwNow = GetTickCount();
if ((dwNow - dwLastChange) < 200) return; // debounce 200 ms
if (getchar() == 0) return; // no key available
int c = getchar();
if (c == 0 || c == EOF) return;
if (c == 0x3B) // VK_F1 == 0x3B
{
SetTagBit("HornQuit", 1); // pulse the ack tag
}
dwLastChange = dwNow;
return;
}
Drawbacks:
-
getchar()in WinCC Runtime blocks on the runtime's stdin; in Web-Client and Softnet deployments it can returnEOFimmediately and silently no-op. - The polled approach consumes CPU cycles and scales poorly with additional hotkeys.
- Operator input captured by an I/O field may be swallowed by the polling task before the I/O field can process it, depending on the input focus model of the deployed runtime.
This method is retained for diagnostic purposes but should not be the production solution.
Method 3: Shortcut Property (Recommended)
The correct, focus-independent implementation is to assign the F-key to the button's Shortcut property. This is the property that WinCC's input dispatcher monitors at the screen level, and it does not require the button to hold focus.
The mechanism is implemented as follows:
- Select the horn-acknowledge push button (e.g.
@BtnHornAckinside@HornQuit.pdl). - In the Properties pane, expand Miscellaneous.
- In the Shortcut field, click the small key icon and press the desired function key. WinCC records the virtual key code (F1 =
0x3B, F2 =0x3C, ..., F12 =0x42, plus modifiers0x10for Shift,0x11for Ctrl,0x12for Alt). - Bind the C action or VB script that resets the internal horn tag to the button's
Mouse Clickevent. TheMouse Clickevent is invoked by the dispatcher whenever the configured Shortcut is intercepted, regardless of focus.
This delivers exactly the behavior the operator expects: F1 acknowledges the horn, and the previously focused object (analog setpoint, recipe value, date picker) remains editable.
Method 4: Event-Driven I/O Field Script
For applications that already maintain a global alarm-active tag (e.g. HornActive), a C or VB script can be bound to the Event → Input/Output value trigger of an off-screen I/O field. The script reads the keyboard state when the tag transitions and pulses the acknowledge bit when F1 is detected.
Configuration steps:
- Create an internal tag
HornActive(Bool) that the alarm logic sets to1on raise and resets on acknowledge. - Add an I/O field bound to
HornActive; place it off-screen or in a hidden layer. - On the I/O field's Event → Output value property, configure a C action:
// C action: Bound to I/O field "HornActive" Output value change event
#include "GlobalDef.h"
void OnHornActiveChanged(void)
{
if (GetTagBit("HornActive"))
{
// Block briefly and probe keyboard state
short sKeyState = GetAsyncKeyState(0x3B); // VK_F1
if (sKeyState & 0x8000)
{
SetTagBit("HornQuit", 1);
}
}
return;
}
Caution: GetAsyncKeyState is a Win32 API and is only available in WinCC Professional C scripts when the Windows API set is included via #include <windows.h>. In WinCC Comfort Panel runtime (WinCE-based), the function is not available, and Method 3 is the only portable path.
Method Comparison
| Method | Focus Independent | Web-Client Support | CPU Overhead | Comfort Panel Support | Recommended |
|---|---|---|---|---|---|
| 1. Set_Focus C action | No (steals focus) | Partial | Low | Yes | No |
| 2. getchar() polling | Yes | No (EOF on Web) | High (100 ms) | No | No |
| 3. Shortcut property | Yes | Yes | None | Yes | Yes |
| 4. I/O field event + GetAsyncKeyState | Yes | Yes (Pro RT only) | Low | No | Conditional |
Step-by-Step: Implementing the Shortcut Method
The following procedure delivers a focus-independent horn-acknowledge hotkey on a WinCC Professional (TIA Portal V16/V17) runtime. The same procedure applies to WinCC Comfort V16/V17 panels with one additional constraint: Shortcut support on Comfort panels is limited to the alphanumeric keys and F1-F12; combinations with Shift/Ctrl/Alt are restricted to certain firmware revisions (V15.1 and later).
-
Create the internal acknowledge tag. In the project tree, open PLC tags → Show all tags → Add new tag. Name it
HornQuit(Bool), address%DB100.DBX0.0or the equivalent internal address. The horn-acknowledge script will pulse this tag for one PLC cycle. -
Create the horn-acknowledge picture window. In the project graphics, create a new picture named
@HornQuit.pdl. Drop a push button named@BtnHornAckon it. Size the picture to 1 x 1 pixel and place it off the visible area, or open it as a picture window from a parent screen and keep its visibility off. -
Bind the C action to the button. On
@BtnHornAck, open Properties → Events → Mouse → Click. Add a C action:
// C action: BtnHornAck OnClick
#include "GlobalDef.h"
void OnBtnHornAckClick(char* lpszPictureName, char* lpszObjectName)
{
SetTagBitWait("HornQuit", 1); // pulse 1 PLC cycle
SetTagBitWait("HornQuit", 0);
return;
}
-
Assign the F1 Shortcut. On
@BtnHornAck, open Properties → Miscellaneous → Shortcut. Click the key icon and press F1 on the keyboard. WinCC writes the virtual key code 0x3B to the property. - Compile and download. Compile the HMI project, transfer the runtime files to the operator station, and start the runtime.
- Verify uniqueness. Right-click the project root, choose Cross-reference → Shortcut to list every object that uses a Shortcut in the project. Resolve any duplicates by reassigning one of the conflicting buttons to a different F-key (F2-F12) or to a Ctrl/Alt combination.
Verification
After implementation, run the following test sequence to confirm the configuration:
- Start the runtime. Navigate to a screen that contains at least one editable I/O field (analog setpoint, recipe value, or numeric parameter).
- Click into the I/O field and confirm the cursor is visible inside it. Do not press Enter or Tab.
- Trigger a horn-active alarm from the PLC (set the relevant alarm bit in the PLC tag table, or use the WinCC simulator's Alarm → Trigger menu). Confirm the horn sounds.
- With the focus still inside the I/O field, press F1 on the keyboard. The horn must silence within one PLC scan cycle.
- Without clicking anywhere, type a new value into the I/O field and press Enter. The new value must be written to the PLC without re-triggering the horn. If the horn re-triggers or the value is rejected, focus has been stolen by the acknowledge button and Method 1 is in use by mistake.
- Repeat steps 2-5 with the I/O field configured as a date picker, dropdown, and slider. The Shortcut method must not interfere with any of them.
Common Failure Modes and Resolutions
| Symptom | Likely Cause | Resolution |
|---|---|---|
| F1 does nothing | Shortcut not assigned; or focus is in a Web-Client pop-up | Re-assign Shortcut in button Miscellaneous; for Web-Client, ensure the screen containing the button is the active browser tab |
| Set_Focus has been used and other I/O fields are locked | Legacy Set_Focus C action still bound to Open Picture event | Remove the Set_Focus call; switch to Shortcut property |
| F1 fires the wrong button | Duplicate Shortcut on two objects in the same hierarchy | Use Cross-reference → Shortcut to find duplicates; reassign one button to F2-F12 or a Ctrl/Alt combination |
| Shortcut works in V16 but not V17 | Shortcut property was moved between releases; or the runtime cache was not cleared | Recompile the HMI project; clear the runtime cache; verify under TIA Portal V17 update 4 or later |
| GetAsyncKeyState returns 0 on Comfort Panel | WinCE runtime does not expose Win32 API | Use Method 3 (Shortcut property) only; do not use Method 4 on Comfort panels |
| Hotkey works on engineering station but not on operator station | Shortcut property not part of the compiled runtime; or filtered by group policy | Recompile with "Generate Shortcut table" enabled; check Windows accessibility settings for sticky-key / filter-key interference |
Virtual Key Code Reference
| Key | Virtual Key Code | Key | Virtual Key Code |
|---|---|---|---|
| F1 | 0x3B | F7 | 0x41 |
| F2 | 0x3C | F8 | 0x42 |
| F3 | 0x3D | F9 | 0x43 |
| F4 | 0x3E | F10 | 0x44 |
| F5 | 0x3F | F11 | 0x57 |
| F6 | 0x40 | F12 | 0x58 |
| Shift modifier | 0x10 | Ctrl modifier | 0x11 |
| Alt modifier | 0x12 | Esc | 0x1B |
To bind a combination such as Ctrl+F1, enter the modifier virtual key code first followed by the function key code in the Shortcut editor's "Extended key sequence" field. WinCC V16/V17 supports up to four modifier keys per Shortcut binding.
Best Practices
- Prefer the Shortcut property over any C-script-based focus manipulation. It is the only mechanism that delivers a true focus-independent hotkey and is supported across all WinCC runtime targets.
-
Centralize the acknowledge button in a single picture window (
@HornQuit.pdl) that is opened globally at runtime start. This makes duplicate-Shortcut detection easier to audit. - Avoid using F1 for horn-acknowledge on systems where F1 is conventionally bound to online help. Reserve F1 for help context and use F2-F12 for operational hotkeys.
- Document every Shortcut binding in a project-level table (screen, object, Shortcut, action) and check it into the engineering repository. This is the only reliable way to detect hotkey collisions before commissioning.
-
Test under the same runtime that will be deployed (WinCC Professional, WinCC Comfort, WinCC Advanced). The Shortcut dispatcher behaves identically across all three, but the helper APIs (
GetAsyncKeyState,getchar) do not.
References in Configuration
For the authoritative specification of the Miscellaneous → Shortcut property and its runtime behavior, consult the TIA Portal WinCC Professional online help and the Siemens Industry Online Support portal. The Shortcut dispatcher is implemented in the WinCC runtime's input manager and is documented under "Configuring operator input → Keyboard operation" in the WinCC Professional system manual.
Why does the F1 key not trigger the horn-acknowledge button even though the script is bound to the Mouse Click event?
Because the Mouse Click event only fires on a real mouse click, not on a key press. To make F1 work, assign F1 to the button's Miscellaneous → Shortcut property. WinCC's input dispatcher will then invoke the configured Mouse Click event whenever F1 is pressed, regardless of which object holds the focus.
Can two push buttons on the same screen use the same F-key Shortcut?
No. WinCC silently fires only the first button found in the object hierarchy and ignores the second. Use the Cross-reference → Shortcut tool in the TIA Portal project tree to find duplicates and reassign one of them to a different F-key (F2 through F12) or to a Ctrl/Alt modifier combination.
Does the Shortcut method work on Comfort Panels, or only on WinCC Runtime Professional?
The Shortcut method works on both. WinCC Comfort Panels (TP, KP, RP series) support F1 through F12 as Shortcuts on firmware V15.1 and later. Ctrl, Alt, and Shift modifier combinations are supported on firmware V16 and later. The implementation procedure is identical to that for WinCC Professional.
Why is the C script that calls Set_Focus locking other input objects on the same screen?
Set_Focus transfers the runtime focus to the target object and keeps it there until another Set_Focus call or a mouse click moves it. While the horn-acknowledge button holds the focus, no other object can receive keyboard events, so I/O fields appear locked. The fix is to remove the Set_Focus call and use the Shortcut property instead.
What virtual key code should I enter for a custom Shortcut binding to a non-F key?
Use the standard Win32 virtual key codes. For example, the Space bar is 0x20, Enter is 0x0D, Escape is 0x1B, the numeric keypad 0 is 0x60, and the letter A is 0x41. Modifier keys use 0x10 (Shift), 0x11 (Ctrl), and 0x12 (Alt). The complete list is documented in the Microsoft Win32 virtual-key codes reference.